If you want to follow along at home, an official Arduino Uno R3 is available HERE. In this new series of lessons, I will be using the sensor and other components found in this KIT.
This is the code we used in this project to switch the LED on and off.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
int LEDPin=8; int buttonPin=12; int buttonRead; int dt=100; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(LEDPin, OUTPUT); pinMode(buttonPin, INPUT); } void loop() { // put your main code here, to run repeatedly: buttonRead=digitalRead(buttonPin); Serial.println(buttonRead); delay(dt); if(buttonRead==1){ digitalWrite(LEDPin,LOW); } if(buttonRead==0){ digitalWrite(LEDPin, HIGH); } } |