This week (23 Oct), you need to bring:

  • Laptop
  • Arduino & cable
  • Breadboard
  • Jumper wires


I will bring:

  • LED lights
  • a pushbutton
  • some resistors


We will see how easy it is to control leds and buttons. – WE USED EXAMPLE “BLINK” AND SAVE IT FOR OURSELVES AS “BLINK5″


When we added another LED (eg to pin 5) and a BUTTON (eg to pin 7), we wanted to wink the extra LED too, and to have some control by the button.

Copy and paste THIS code into the edit window on your Arduino program:


<<<< FROM HERE …

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// And our NEW LED on (say) pin 5:

int led5 = 5;

// And a NEW BUTTON on pin 7:
int button = 7;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);

pinMode(led5, OUTPUT);                    // Two line WE add
pinMode(button, INPUT_PULLUP);            // to define how pins 5 an7 will be used

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
digitalWrite(led5, LOW);         // WE added.  Led on pin 5 will wink opposite to inbuilt Led on 13
delay(500);               // wait
digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
if (digitalRead(button) == LOW)
digitalWrite(led5, HIGH);         // WE added.   Led5 keeps winking ONLY on button press
// otherwise it never gets turned on again, stays LOW

delay(500);               // wait



<<<<<<<< TO HERE