Below is part of a much bigger sketch that I've got all working except for the logic below that seems to disregard whether the value of the switch is high or low. The serial monitor only display regardless if the switch is open or closed
int flag = 0;
const int brksw = 11;
int brkswState = 0;
void setup() {
Serial.begin(9600);
pinMode(brksw, INPUT);
}
void loop() {
brkswState = digitalRead(brksw);
if (brkswState == LOW) {
flag = 1;}
if (brkswState == HIGH) {
flag = 9;}
Serial.println(flag);
}
11 posts - 4 participants