/*
HEADER: What's this thang were doing today?
Digital inputs, and button, and toggles, and state variables and state machines
OH MY
Today we are designing a attendance counter for the Mines football games
The counter, should increase the count
with each button click keeping track of attendance.
An LED should also turn on with a button pressand
then off with the preceeding button press
*/
//Global pin and variable delcaration
//Pins Needed
int LEDPin = 13;
int ButtonPin = 2;
bool toggle = 0;
//vars needed
int count = 0;
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);
pinMode(ButtonPin,INPUT_PULLUP);
//INPUT_PULLUP switches the logic of the button --> adds 20 kohms to the circuit
//When button is pressed -> LOW
//When not pressed -> HIGH
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
//part 1a -> button press
/*if(digitalRead(ButtonPin)==LOW){
count += 1;
digitalWrite(LEDPin, HIGH);
delay(100);
}
else{
digitalWrite(LEDPin, LOW);
}
Serial.println(count);
*/
if(digitalRead(ButtonPin)==LOW){
toggle = !toggle;
count += 1;
delay(200);
}
else{
}
if(toggle==1){
digitalWrite(LEDPin, HIGH);
}
else{
digitalWrite(LEDPin, LOW);
}
Serial.println(count);
}