PDA

View Full Version : blinking?



blaze15301
03-12-2011, 03:57 AM
i made a smiley face out of leds. and i would like to make one eye blink, but when i change the code to make pin 8 blink all the leds blink or they turn on 1 at a time. any suggestions.


// blinking led 1
#define LED 13 //led connected to 13

void setup ()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT); // 11 is output
pinMode(10, OUTPUT); // 10 is output
pinMode(9, OUTPUT); //9 is output
pinMode(8, OUTPUT); // 8 is output

}

void loop()
{
digitalWrite(13, HIGH); // turns led on
delay(3000);
digitalWrite(12, HIGH);
delay(3000);
digitalWrite(11, HIGH); // 11 is on
delay(3000);
digitalWrite(10, HIGH); // 10 is on
delay(3000);
digitalWrite(9, HIGH); // 9 is on
delay(3000);
digitalWrite(8, HIGH); // 8 is on
delay(3000);


digitalWrite(13, LOW); // turn led off
delay(3000);
digitalWrite(12, LOW);
delay(3000);
digitalWrite(11, LOW); // 11 is off
delay(3000);
digitalWrite(10, LOW); // 10 is off
delay(3000);
digitalWrite(9, LOW); //9 is off
delay(3000);
digitalWrite(8, LOW); //8 is off
delay(1500);
}




#define LED 13 // defines pin 13 as LED

void setup(){

pinMode(13, OUTPUT); // 13 is output
pinMode(12, OUTPUT); // 12 is output
pinMode(11, OUTPUT); // 11 is output
pinMode(10, OUTPUT); // 10 is output
pinMode(9, OUTPUT); //9 is output
pinMode(8, OUTPUT); // 8 is output

}

void loop(){

digitalWrite(13, HIGH); //13 is on
digitalWrite(12, HIGH); //12 is on
digitalWrite(11, HIGH); // 11 is on
digitalWrite(10, HIGH); // 10 is on
digitalWrite(9, HIGH); // 9 is on
digitalWrite(8, HIGH); // 8 is on

digitalWrite(13, LOW); // 13 is off
digitalWrite(12, LOW); // 12 is off
digitalWrite(11, LOW); // 11 is off
digitalWrite(10, LOW); // 10 is off
digitalWrite(9, LOW); //9 is off
digitalWrite(8, LOW); //8 is off


ive tried both of those and neither do what i want. the bottom one just leaves all the leds lit up.

also this is just a gateway to a much much much much bigger project.

SXRguyinMA
03-12-2011, 09:16 AM
try this :D


// blinking led 1
#define LED 13 //led connected to 13

void setup ()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
}

void loop(){
digitalWrite(13, HIGH); // turns led on
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
delay(1500);
digitalWrite(8, LOW); //8 is off
delay(1500);
}

crenn
03-12-2011, 10:13 AM
try this :D



Or this:


// blinking led 1
#define LED 13 //led connected to 13
unsigned char state=HIGH;

void setup ()
{
for(int i=8;i<=13;i++){ // This for loop starts with a varible, in this case i, I initialise the varible with 8 (so it's pin 8. As the code between the {} completes, i is incremented by 1 (i++) and then i is checked if it is less than or equal to 13. If it is, the code in between {} will run with the new value of i, 9. This will continue until the condition (i<=13) is not true, then the code will pass the loop.
pinMode(i, OUTPUT); // sets the pin to output whatever value i is, (initially 8)
digitalWrite(i, HIGH); // then it sets that pin high, which will turn the LED on.
}
}

void loop(){
digitalWrite(8, state); //Writes the new 'state' to pin 8, it initially starts as HIGH
state^=HIGH; // Then after it's written the new state it flips that state to LOW if it was HIGH, or vice versa. It does this with an exclusive OR bitwise operation, XOR.
delay(1500); //wait for 1.5s (1500ms) before doing loop() again.
}

SXRguyinMA
03-12-2011, 05:19 PM
that as well. I was thinking more in terms of him being a noob to arduino, and half that stuff you posted I don't even know lol

blaze15301
03-12-2011, 06:05 PM
[QUOTE=SXRguyinMA;322431]that as well. I was thinking more in terms of him being a noob to arduino, and half that stuff you posted I don't even know lol[/QUOTi sort of understand some of the code crenn posted.

crenn
03-12-2011, 07:21 PM
I'll edit it and make some comments.