Heartbeat Cakes

heartbeat copy

 

/*
 Robot Cake
 By: Nathan Seidle
 SparkFun Electronics
 Date: March 2nd, 2015
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
 

 */

const byte LED1 = 5;
const byte LED2 = 6;
const byte LED3 = 9;
const byte LED4 = 10;

int brightness = 0;
int fadeAmount = 1; //The amount of brightness the LED changes each loop

long startTime = 0; //Allows us to define the overall cycle time

#define TIME_BETWEEN_FADES 15 //30 is pretty good
#define MIN_BRIGHT 5

void setup()
{
 //Setup UART
 //Serial.begin(9600);
 //Serial.println("Heart beat");

 pinMode(LED1, OUTPUT);
 pinMode(LED2, OUTPUT);
 pinMode(LED3, OUTPUT);
 pinMode(LED4, OUTPUT);
}

void loop()
{
 fadeAmount = abs(fadeAmount);
 for(brightness = MIN_BRIGHT ; brightness < 255 ; )
 {
 if(brightness > 200)
 brightness += fadeAmount * 5;
 else if(brightness > 150)
 brightness += fadeAmount * 4;
 else if(brightness > 100)
 brightness += fadeAmount * 3;
 else if(brightness > 75)
 brightness += fadeAmount * 2;
 else 
 brightness += fadeAmount;
 
 if(brightness > 255) brightness = 255;
 
 updateLEDs(brightness);
 
 delay(TIME_BETWEEN_FADES);
 }

 fadeAmount *= -1;
 for( ; brightness > MIN_BRIGHT ; )
 {
 if(brightness > 200)
 brightness += fadeAmount * 5;
 else if(brightness > 150)
 brightness += fadeAmount * 4;
 else if(brightness > 100)
 brightness += fadeAmount * 3;
 else if(brightness > 75)
 brightness += fadeAmount * 2;
 else 
 brightness += fadeAmount;
 
 //if(brightness < MIN_BRIGHT) brightness = MIN_BRIGHT;

 updateLEDs(brightness);
 
 delay(TIME_BETWEEN_FADES);
 }
 
 //updateLEDs(0); //Turn off LEDs

 //Hang out until the end of this period
 delay(1500);

}

void updateLEDs(int brightLevel)
{
 analogWrite(LED1, brightLevel);
 analogWrite(LED2, brightLevel);
 analogWrite(LED3, brightLevel);
 analogWrite(LED4, brightLevel);
}

Comments are closed.