Wednesday, April 13, 2016

Arduino/Genuino 101 example to read button and turn ON/OFF LED


Simple example of Arduino/Genuino 101, to read button (on pin 6) and control LED (on pin 7) accodingly.

Connection:

_101_button_led.ino
/*
 * Arduino/Genuino 101 example
 * to read button and turn ON/OFF LED accordingly
 */

int LED = 7;
int BTN = 6;

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(BTN, INPUT_PULLUP);

  //indicate program start
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  delay(200);
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
}

void loop() {
  digitalWrite(LED, !digitalRead(BTN));
  delay(100);
}


No comments:

Post a Comment