Pages: 1 [2]   Go Down
Author Topic: Ladyada's multi-button checker - how to?  (Read 1442 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code is send over ethernet to the second arduino.
Code:
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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

What are you REALLY trying to do?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to figure out where the problem is.
I thought that:
Code:
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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: 1 [2]   Go Up
Jump to: