Hallo,
I am experiencing some strange behavior which I would like some help to understand.
I am playing around with reading the input from a button, but as the button does not perfectly fit into my prototype board it sometimes falls out. When it does, the state of the pin its connected to changes from HIGH to LOW, and back again for an indefinite amount of time, but only if im also writing a serial message. For it to happen, the wire needs to be plugged into the board, but not to anything on the other side (so the problem is not the button popping in an out, the problem can be replicated without the button)
To make it even more strange, it only happens when i have my hands close to the board!
Please see the attach photos.
void setup()
{
// Configure the board
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(4, INPUT);
Serial.begin(9600);
digitalWrite(8, LOW);
}
void loop()
{
boolean buttonPressed = false;
if(digitalRead(4) == LOW)
{
digitalWrite(8, HIGH);
buttonPressed = true;
}
else
{
digitalWrite(8, LOW);
Serial.println("button NOT pressed");
}
if(buttonPressed)
{
Serial.println("button pressed");
delay(250);
Serial.flush();
}
}