Go Down

Topic: Double Blink (Read 1 time) previous topic - next topic

Sploosh

Ahoy there! A newbie here, just playing around with Arduino for the first time. I'm trying to figure out how to make my LED double blink, kind of like a heartbeat? Please could anyone show me how to do that, or put me in the right direction?

Thanks for any help you can give! I posted the code below.

Code: [Select]
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

djjoshuad

This probably belongs in a different forum, but here's your answer:

replace this:

Code: [Select]

void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}


with this:

Code: [Select]

void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(400);               // wait for 400ms
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(100);               // wait for 100ms
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);               // wait for 500ms
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}


This particular pattern will blink twice within one second (with the second blink slightly longer than the first, like a heartbeat), then be off for a full second.  I haven't tested it but it should be pretty close to a heartbeat style blink.  Just play with the delays until you get the pattern you want.  Enjoy!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy