Wednesday, October 24, 2012

Arduino - Blinking LED

This exercise started with turning an LED (Light Emitting Diode) on and off repeatedly to create a little blinking effect.

Hooked up a 5mm Yellow LED  to my breadboard along with 3 wires and a 330 Ohm Resistor. The LED's longer  lead is the positive (+) side, the shorter is the negative (-). 

One wire was plugged in alignment to the positive lead and the other end went into the 13th input on the arduino itself. 

The second wire went from the ground (GND) to a negative on the breadboard.

The third wire went from 5 volts (5V).

Connected that up via USB to the computer and uploaded the program:

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


CHANGES:
  • BLINK TIME
    • Change delay
      • delay(seconds * 1000)
      • high delay for on
      • low delay for off
  • BRIGHTNESS
    • Must be in an ANALOG (~) numbered pin
    • analogWrite (led, new number);
      • new number = any number between 0 and 225
      • 0 = off
      • 255 = on

No comments:

Post a Comment