The 3th in a series of tutorials to help you understand the basics of the Arduino uno. In this session we will be covering if statements in the context of digitalReads. By the end of this session you will be able to write code to turn and LED on and off using a button. You can apply this theory to a number of more complex functions which we will go over in the next tutorial.
int button = 7;
int led = 8;
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(button, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(button) == HIGH) {
digitalWrite(led, HIGH);
}
else{
digitalWrite(led, LOW);
}
}