본문 바로가기

IoT/Intel Edison

Grove - Button and LED

Grove - Button and LED

This example shows you how to turn on or off an LED via button.

Hardware Required
- Intel® Edison Module
- Arduino* expansion board
- Grove Base Shield v2
- Grove Button(P)
- Grove LED Socket Kit

Circuit



Schematic



Code 


const int buttonPin = 3;     // the number of the pushbutton pin
const int ledPin =  7;         // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // start serial port
  Serial.begin(115200);
  Serial.println("LED Demo");

  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH); 
    //Serial.println("Pin-HIGH"); 
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
    //Serial.println("Pin-LOW"); 
  }
  
  //delay(500);               // wait for a 0.5 second
}

See  Also
 
Reference sites


'IoT > Intel Edison' 카테고리의 다른 글

Grove - Sound Sensor  (0) 2015.01.24
Grove - Buzzer  (0) 2015.01.24
Blink LED in Intel® Edison for Arduino expansion board  (0) 2015.01.19
Connect the Intel Edison device to WiFi  (0) 2014.12.26
Grove Starter Kit Plus - Intel® IoT Edition  (0) 2014.12.20