Introduction
The EagLED comes included with a momentary pushbutton.
In this guide, learn to use the EagLED's pushbutton to turn an LED on and off.
Complete this guide to master the basics involved in using the pushbutton with EagLED.
-
-
void setup() { pinMode(ledPin,OUTPUT); // Set the LED Pin as an output pinMode(buttonPin,INPUT_PULLUP); // Set the pushbutton as an input }
-
const int ledPin = 3;// the LED pin const int buttonPin = 2;// the pin our push button is on void setup() { pinMode(ledPin,OUTPUT); // Set the LED Pin as an output pinMode(buttonPin,INPUT_PULLUP); // Set the pushbutton as an input } void loop() { int digitalVal = digitalRead(buttonPin); // Take a reading if(digitalVal == HIGH) { digitalWrite(ledPin,LOW); //Turn the LED off } else { digitalWrite(ledPin,HIGH);//Turn the LED on } }
-
const unsigned int ledPin = 3; const unsigned int buttonPin = 2; int buttonState = 0; int oldButtonState = LOW; int ledState = LOW; void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT_PULLUP); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState != oldButtonState && buttonState == HIGH) { ledState = (ledState == LOW ? HIGH : LOW); digitalWrite(ledPin, ledState); delay(50); } oldButtonState = buttonState; }