Sunday, December 22, 2013
Wednesday, February 22, 2012
Flashing Leds solution
After posting on Lets make Robots looking for some info on getting the code to work ..... I got a reply with this code which dose the job .....
int del=1000;
void setup()
{
for (int i =2; i<10;i++)
{
pinMode(i,OUTPUT);
}
}
void loop()
{
for (int i=2; i<=5; i++)
{
lightUp(i,11-i);
}
for(int i=5; i>=2; i--)
{
lightUp(i, 11- i);
}
}
void lightUp(uint8_tpin1,uint8_tpin2)
{
digitalWrite(pin1, HIGH);
digitalWrite(pin2, HIGH);
delay(del);
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
}
int del=1000;
void setup()
{
for (int i =2; i<10;i++)
{
pinMode(i,OUTPUT);
}
}
void loop()
{
for (int i=2; i<=5; i++)
{
lightUp(i,11-i);
}
for(int i=5; i>=2; i--)
{
lightUp(i, 11- i);
}
}
void lightUp(uint8_tpin1,uint8_tpin2)
{
digitalWrite(pin1, HIGH);
digitalWrite(pin2, HIGH);
delay(del);
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
}
Those of you that follow tronixstuff will have seen the
tutorials on leds ... im trying them out
at the moment. First tutorial is http://tronixstuff.wordpress.com/2010/04/04/getting-started-with-arduino-chapter-zero/
So I did this the long way (shown on chapter 0) and then used the ... for
.... example which is the shorter version of code to do
the same thing (shown on chapter 1)
Well I wanted to flash my leds in a different pattern ... eg
led 2,3,4,5 > .........
<9,8,7,6 so I had tried doing this with the for code but ran into problems ... where as doing it the long way was
simple but long.
One thing I did change was with the int(I =2 ; I <=9 .... I changed this to int(I =2 ; I <=5
.... and then added a int(t=6 ; t <=9
But I cant get it to work the way I want ... it runs
allright but not the way I planned it to
Have the two code versions here .... first is the long way that
works the way I want it ... second is the short way that only part works ...
watch video and see one side works fine other side dosent (swap two lines of code with each other and
working side swaps)
int del=100; // sets a default delay time, 1000 milliseconds
(one second)
void setup()
{
// initialize the digital pins as outputs:
// later on there will be easier ways to do this
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
// the loop() method repeats indefinitely until you turn off
the power
void loop()
{
digitalWrite(2, HIGH);
digitalWrite(9, HIGH);
delay(del);
digitalWrite(2, LOW);
digitalWrite(9, LOW);
digitalWrite(3, HIGH);
digitalWrite(8, HIGH);
delay(del);
digitalWrite(3, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
delay(del);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(7, HIGH);
digitalWrite(4, HIGH);
delay(del);
digitalWrite(7, LOW);
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
delay(del);
digitalWrite(8, LOW);
digitalWrite(3, LOW);
digitalWrite(2, HIGH);
digitalWrite(9, LOW);
digitalWrite(2, LOW);
Second version ....
int del=100;// sets a default delay time, 1000 milliseconds
(one second)
{
// initialize the digital pins as outputs:
for (int i = 2; i<=5 ; i++)
for (int t = 6;
t<=9 ; t ++)
{
pinMode(i, OUTPUT);
pinMode (t,
OUTPUT);
} // end of setup
void loop()
{
for (int t = 9; t>=6; t--)
digitalWrite(t,
HIGH);
digitalWrite(i,
HIGH);
digitalWrite(t, LOW);
}
for (int t = 6; t<=9; t++)
digitalWrite(t,
HIGH);
digitalWrite(i,
HIGH);
digitalWrite(t, LOW);
}
Tuesday, February 14, 2012
Photoresistor to Control servo
Was looking up information on photoresistors and found some good info on this site http://www.societyofrobots.com/schematics_photoresistor.shtml .... so I decided to make the voltage divider i came across. Made it up on a breadboard with a led .... idea was to get a led to light up when less light shined on the photoresistor ... worked very well and was easy to set up.
Then thought wouldnt it be nice to connect this to my Arduino board and get it to control a servo eg when less light lands on sensor the servo would turn. Was'nt sure if it was possible to do .... but surprisingly i figured it out and got it to work.
Still have some work to do on it ... as its light dependent ... and light changes throughout the day what would work at one time in the day would not work at a later time as the readings programmed into the arduino change .
But it dose work very well for a few hours until the light has changed. So adding the video i made so take a look and see.
Then thought wouldnt it be nice to connect this to my Arduino board and get it to control a servo eg when less light lands on sensor the servo would turn. Was'nt sure if it was possible to do .... but surprisingly i figured it out and got it to work.
Still have some work to do on it ... as its light dependent ... and light changes throughout the day what would work at one time in the day would not work at a later time as the readings programmed into the arduino change .
But it dose work very well for a few hours until the light has changed. So adding the video i made so take a look and see.
Thursday, February 9, 2012
Monday, February 6, 2012
HY-SRF05 Sensor
Ok got my HY-SRF05 distance sensor today ... and after a bit of googling managed to figure out how to wire it up to get it working. Works fine with only a few glitch readings .... next step was to get it to work with a servo. This proved to be a bit trickier ... but have just managed to put a bit of code together to do this. Have got it that if it detects a object = or less than 10cm away the servo will turn to the left ... if no object in front of it or further away than 10cm it will rotate servo back to the front. Nothing amazing about this code but hopefully it is a start to writing a complete object detection and avoidance program.
Just trying out sensor on servo .... will have to work on how to mount this as cant be using blue tack ........
Monday, January 30, 2012
Subscribe to:
Posts (Atom)