My little Arduino! Isn’t he cute?

By pauloppenheim

I’m not sure it’s a he. But I made a thing! With a light! I am so excited, I wanted to share my simple code. The tweet:

I made the first “Getting Started with Arduino” example into the “breathing LED” on sleeping apple laptops. I like this little thing.

and the code:

// Example 01 : Blinking LED
//
// Copy and paste this example into an empty Arduino sketch

#define LED 13   // LED connected to
                 // digital pin 13
int i = 1;

void setup()
{
  pinMode(LED, OUTPUT);    // sets the digital
                           // pin as output
}

void loop()
{
  double i_f = i;
  double max = 12.0;
  double val = (cos(i_f/30.0)*.999 + 1.0) * (max/2);
  digitalWrite(LED, HIGH);   // turns the LED on
  delay(val);               // waits for a second
  digitalWrite(LED, LOW);    // turns the LED off
  delay(max - val);               // waits for a second
  i++;
}

It’s nothing fancy, especially if you code all day (at which point this is probably less than you have to type to even setup coding for the day), but the important thing to note is that this shit turns on a LIGHT.

On my DESK.

OK, stop making fun of me.

Leave a Reply