Pages: [1]   Go Down
Author Topic: Double Blink  (Read 831 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*
  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
}
Logged

Corinth, TX
Offline Offline
Jr. Member
**
Karma: 1
Posts: 92
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

replace this:

Code:
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:
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!
Logged

Pages: [1]   Go Up
Jump to: