Go Down

Topic: Ladyada's multi-button checker - how to? (Read 1 time) previous topic - next topic

MrGlasspoole

The code is send over ethernet to the second arduino.
Code: [Select]
if (justreleased[0]) {
      justreleased[0] = 0;
      Serial.print(i, DEC);
      Serial.println(" Just released");
}
Sometimes shows:
5 Just released
3 Just released
2 Just released
3 Just released
in the serial Monitor.
But also if i see for example "5 Just released" i receive the code in Mosquitto until it stops working.

PaulS

Why are you explicitly testing the 0 element, and then printing i?

What are you REALLY trying to do?

MrGlasspoole

I'm trying to figure out where the problem is.
I thought that:
Code: [Select]
if (justpressed[0]) {
justpressed[0] = 0;
Serial.print(i, DEC);
Serial.println(" Just pressed");
client.publish("foo/shower","0"); // Turn off Shower Light
// remember, check_switches() will CLEAR the 'just pressed' flag
}
shows me if the first button (pin 54 on the Mega) is pressed?
It's the only button that is connected at the moment.
But sometimes i get:
5 Just pressed
3 Just pressed
2 Just pressed
instead of "0 Just pressed" if i press button 0/54

The funny thing is that also if the serial monitor says for example "3 Just pressed", my button 0 code works.

PaulS

You are testing the 0 switch, and then printing some random value of i. Why is that so hard to see? Or fix?

Go Up