Having a problem with something simple.
I have a board programmed: press a button, LED13 lights up and it triggers a soundfile in MaxMSP.
But the LED13 is behaving erratically, it keeps lighting on and off and often does not repond to the buttonpress. I have no idea. Have a different board programmed in the same way, with the same circuit which works prefectly. Any ideas?
Code:
int ledPin = 13; // choose the pin for the LED
int inPin = 7; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
void setup() {
Serial.begin(57600);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
}
void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
Serial.println("A");
}
else {
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.println("M");
}
I'm inclined to guess the two boards are not actually wired identically.... but in any case, provide a schematic. Specifically, how is the button wired?- got a pullup or pulldown? If it's high when released that implies a pullup, but from the code it's not the internal one, so is it wired to ground with a pullup?