//pairs needed
int LEDPin = 13;
int ButtonPin = 2;
//vars needed
int count = 0; // helping us count how many times you push the button
bool toggle = 0;
int PrevState = 0; //needs to be updated each iteration
int CurState = 0; //needs to be updated each iteration
void setup() {
// put your setup code here, to run once:
//tell arduino what pins are being used and how (pinMode) and start serial monitor
pinMode(LEDPin, OUTPUT); // set LEDPin to actuator
pinMode(ButtonPin, INPUT_PULLUP); //set button to a sensor
//BUT INPUT_PULLUP swithces button logic --> add 20 kohms to the circuit. Limits
//Current; not too much power is being pulled
//when the button is pressed ---> LOW
//when not pressed ---> HIGHT
//Start Serial Monitor
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
/*
//Part 1 --> button press
if(digitalRead(ButtonPin)==LOW){
//if LOW --> Button Pressed ---> do stuff coded below
count = count + 1; //increasing count by 1
digitalWrite(LEDPin,HIGH);
delay(100); //100 ms delay
}
else{
//button not pressed --> HIGH
digitalWrite(LEDPin, LOW); //Turn off LED
}
Serial.println(count);
*/
/*
//Part 2
if(digitalRead(ButtonPin)==LOW) {
toggle = !toggle;
//switch from 0 to 1 or vice-versa
count = count + 1;
delay(200);
}
else{
//button not pressed --> High
}
if(toggle == 1) {
digitalWrite(LEDPin, HIGH); //LED on
}
else{
digitalWrite(LEDPin, LOW); //LED off
}
Serial.println(count);
*/
/*
//Part 3
CurState = digitalRead(ButtonPin);
if(CurState < PrevState) {
toggle = !toggle;
count = count + 1;
delay(200);
}
else{
//button not pressed
}
//now true toggle
if(toggle == 1){
digitalWrite(LEDPin, HIGH); //LED on
}
else{
digitalWrite(LEDPin, LOW); //LED off
}
Serial.println(count);
PrevState = CurState;
//overwriting previous state each time with our current state --> old state for next iteration
*/
}