close fullscreen

Blink Example

help edit space_dashboard

Out of the box, you only really have the LED for output, so get the example called Blink, then attempt to create a modified version, I called my first variation Blink2, here is the code:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://www.arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

void fade(int up, int n) {
  int i,j;
  int x = n >> 3;

   for(i=0; i<x; i++) {
    int on = i,off = x-i;
    if (!up) { int x=on; on=off; off=x; }
    on = on*on; off = off+off;
    for(j=0; j<10; j++) {
    digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(on);
    digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
    delay(50-on);
   }
  }
}

// the loop function runs over and over again forever
void loop() {
  fade(1,256);
  fade(0,256);
}