I just created a heartbeat for my standalone Arduino based hardware.
The code (based on this example) can blink a LED givin a better sense of heartbeat (instead flashing). In addition runs without utilizing the delay function.
Its a noob solution but it may be useful for some users.
/* Heartbeat
Based on example BlinkWithoutDelay http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
Turns on and off a light emitting diode(LED) connected to a digital
pin, without using the delay() function. This means that other code
can run at the same time without being interrupted by the LED code.
Created JAN 2011
by Nikos Georgousis
Original code authors
created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
*/
// constants won't change. Used here to
// set pin numbers:
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)
long interval2 = 50; // this second interval variable is for light duration
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
if (ledState == LOW) // if the led is OFF then check if its time to blink it
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
ledState = HIGH;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
else // if the led is ON wait just a shorter period of time (interval2) and turn it OFF
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval2) {
// save the last time you blinked the LED
previousMillis = currentMillis;
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
}
Cheers