I found a code online that uses a button as a toggle to change the state of an LED. It's done through clicking the button which changes the "state variable" and then the LED state changes accordingly to the "state variable".
I would like to manipulate the code to not use the LED, but only to use the button to change the state variable and print the state of the "state variable". If you don't understand what I'm trying to ask, please reply to this post.
Here is the code I found on Eleccircuit.com:
int ledPin = 13; // the number of the pushbutton pinint buttonPin = 2; // the number of the LED pin boolean buttonState; boolean lastState;boolean state = HIGH; // variable for first status void setup() { pinMode (buttonPin,INPUT); // initialize the pushbutton pin as an input: pinMode (ledPin,OUTPUT); // initialize the LED pin as an output:} void loop() { reading = digitalRead(buttonPin); if ( reading == LOW && lastState == HIGH ) { delay (10); // To solve the The problem switch bounce if (digitalRead(buttonPin) == LOW) state = !state; } digitalWrite(ledPin,state); lastState = reading; }