Using a button to change a state variable.

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; }

Always show us your current, complete sketch.

Properly formatted!

I'm not sure what to do. I understand the "If" statements but I'm not sure how to incorporate a serial.print command.

I am very new to Arduino.

Stop cross-posting and attach your code properly.

Huy-LT:
I'm not sure what to do. I understand the "If" statements but I'm not sure how to incorporate a serial.print command.

What do you mean?

Serial.println(whateverVariableYouWantToPrint);

I understand what I did wrong.

I didnt understand the 'ledstate' variable.

I could had implemented a section that said:

if(ledState == HIGH){
Serial.println("Led State = HIGH")