Trouble Printing boolean values
Posted: Thu Oct 18, 2018 2:53 pm
I was trying to learn more about Interrupts, so I down loaded the simple Sketch, with the intention of playing with it by making some changes. So I added the print statements for diagnostics. To my surprise I am not printing the Boolean values for pins 13 & 2. (Yes I know I should have debounced the switch - not the issue here.)
Here is my code:
const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}
void loop() {
delay(5000);
Serial.print("state = ");
Serial.println(state);
digitalWrite(ledPin, state);
}
void blink() {
Serial.print(" interruptPin = ");
Serial.println(interruptPin);
Serial.print("ledPin = ");
Serial.println(ledPin);
state = !state;
}
Here is my serial monitor output:
state = 0
state = 0
interruptPin = 2
ledPin = 13
state = 1
interruptPin = 2
ledPin = 13
state = 0
state = 0
state = 0
Can someone tell me how I can print the Boolean values for Pins 13 and 2 instead of the pin numbers.
Here is my code:
const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}
void loop() {
delay(5000);
Serial.print("state = ");
Serial.println(state);
digitalWrite(ledPin, state);
}
void blink() {
Serial.print(" interruptPin = ");
Serial.println(interruptPin);
Serial.print("ledPin = ");
Serial.println(ledPin);
state = !state;
}
Here is my serial monitor output:
state = 0
state = 0
interruptPin = 2
ledPin = 13
state = 1
interruptPin = 2
ledPin = 13
state = 0
state = 0
state = 0
Can someone tell me how I can print the Boolean values for Pins 13 and 2 instead of the pin numbers.