Results 1 to 6 of 6

Thread: blinking?

  1. #1
    Case Wizard blaze15301's Avatar
    Join Date
    May 2010
    Location
    usa
    Posts
    905

    Default blinking?

    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.
    Quote Originally Posted by AmEv View Post
    Or are you talking about vending machine choice C-4?

    mmmmm... skittles....
    bench mark software.

    video bios flashing guide

  2. #2
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: blinking?

    try this

    Code:
    // 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);
    }

  3. #3
    Fox Furry crenn's Avatar
    Join Date
    Apr 2005
    Location
    In the shadows behind you
    Posts
    4,067

    Default Re: blinking?

    Quote Originally Posted by SXRguyinMA View Post
    try this
    Or this:

    Code:
    // 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.
    }
    Antec Sonata II | Pioneer DVR-212
    Good news! You can follow my website or follow me on twitter!

  4. #4
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: blinking?

    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

  5. #5
    Case Wizard blaze15301's Avatar
    Join Date
    May 2010
    Location
    usa
    Posts
    905

    Default Re: blinking?

    [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.
    Quote Originally Posted by AmEv View Post
    Or are you talking about vending machine choice C-4?

    mmmmm... skittles....
    bench mark software.

    video bios flashing guide

  6. #6
    Fox Furry crenn's Avatar
    Join Date
    Apr 2005
    Location
    In the shadows behind you
    Posts
    4,067

    Default Re: blinking?

    I'll edit it and make some comments.
    Antec Sonata II | Pioneer DVR-212
    Good news! You can follow my website or follow me on twitter!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •