- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Simple Pushbutton on off Project 3Arduino Uno - 01Breadboard - 01220 Ohm Resistors - 02LED - 01Push Button Switch - 01Jumper wires Arduino Sketch
const int button = 2; // pin where we connect the buttonconst int led =3; // pin where we connect the LEDint ledflag=0; // LED status flagvoid setup() { pinMode(button,INPUT); // define button as an input pinMode(led,OUTPUT); // define LED as an output digitalWrite(led,HIGH); // turn output ON just in case}void loop() { if (digitalRead(button)==HIGH){ // if button is pressed if (ledflag==0) { // and the status flag is LOW ledflag=1; // make status flag HIGH digitalWrite(led,HIGH); // and turn on the LED } // else { // otherwise... ledflag=0; // make status flag LOW digitalWrite(led,LOW); // and turn off the LED } delay(2000); // wait a sec for the } // hardware to stabilize} // begin again
const int button = 2; // pin where we connect the button
const int led =3; // pin where we connect the LED
int ledflag=0; // LED status flag
void setup() {
pinMode(button,INPUT); // define button as an input
pinMode(led,OUTPUT); // define LED as an output
digitalWrite(led,HIGH); // turn output ON just in case
}
void loop() {
if (digitalRead(button)==HIGH){ // if button is pressed
if (ledflag==0) { // and the status flag is LOW
ledflag=1; // make status flag HIGH
digitalWrite(led,HIGH); // and turn on the LED
} //
else { // otherwise...
ledflag=0; // make status flag LOW
digitalWrite(led,LOW); // and turn off the LED
}
delay(2000); // wait a sec for the
} // hardware to stabilize
} // begin again
Comments
Post a Comment