//Jim and Gab Activity 2: LED with Switch
/*In the previous activity, we created a circuit that uses LED light
and the goal was to turn it on, and off, in an alternating way so
it blinks. Now, we integrate LED with a switch. The system will work in
a way that the LED will turn on i and only if the switch is pressed.*/
const int ledPin = 13;
const int switchPin = 2;
/*To do this, fist we assigned pins 13 as the pin for LED, which is also
our output, and 2 for the switch. The switch will serve as the input
in the system. This will work in a way that there should be an output
(LED turned on) whenever there is an input (switch pressed)*/
int switchState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT_PULLUP);
}
void loop() {
//The state of the switch is being monitored until such time that it is activated.
//When that happens, the LED will light on.
switchState = digitalRead(switchPin);
/*To turn the LED on when the switch is pressed and off if not,, we simply
employ if-else statement. The condition (if) was that the LED will only
light on when the switch is pressed, otherwise, it will turn off*/
if (switchState == LOW) {
// To turn the LED on when the condition is satisfied, we set the command below.
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(ledPin, LOW);
}
delay(500);
}
/* This is still far from greatness, but great things start from small beginnings (Milo)
We might be still far, but we are already far from arrogance. This is still
a good thing for us. A nice thing. A nice start.*/
// Jim & Gab