i found the Ladyada's multi-button checker: http://www.adafruit.com/blog/2009/10/20/example-code-for-multi-button-checker-with-debouncing/First thing i don't get is how i can trigger something with the code (for example turn on an LED).And the second thing i don't understand is that interrupts are used on all the pins in the second example.

As long as i press the button if i use "pressed".So how to make sure it gets send just one time?

Check justreleased instead of pressed. It will tell you that the button has been released and will not be true again until the button is pressed and released again. Or check the value of justpressed to find out if the button has just been pressed and may or may not have been released. Which way you do it depends on whether you want something to happen when a button is pressed or when it is released.

Please do not send me PMs asking for help. Post in the forum then everyone will benefit from seeing the questions and answers.

if (justreleased[i]) { justreleased[i] = 0; // remember, check_switches() will CLEAR the 'just pressed' flag }It works a view times and then it stops working.And how do i make it that the light goes on when i press and send my code just one time?

But here is the whole thing:I want to switch the light from one Arduino on another Arduino via MQTT over my windows server.This is the code that i have on my Mega 2560 where the light is connected:

// Start up the Dallas Temperature library sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement

// Connect to MQTT Broker, give it Switch-O-Matic as the name if (client.connect("Switch-O-Matic")) { // Publish a message to the status topic client.publish("status","Switch-O-Matic is now online"); // Listen for messages on the control topic client.subscribe("foo/#"); }

#define DEBOUNCE 10 // button debouncer, how many ms to debounce, 5+ ms is usually plenty// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etcbyte buttons[] = {14, 15, 16, 17, 18, 19}; // the analog 0-5 pins are also known as 14-19// This handy macro lets us determine how big the array up above is, by checking the size#define NUMBUTTONS sizeof(buttons)// we will track if a button is just pressed, just released, or 'currently pressed' volatile byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];

// Start up the Dallas Temperature library sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement

// Connect to MQTT Broker, give it Bath-O-Matic as the name if (client.connect("Bath-O-Matic")) { // Publish a message to the status topic client.publish("status","Bath-O-Matic is now online"); }

}}At the moment the DS18B20's are just to set unique MAC addresses.On my Windows 2012 Server i have Mosquitto running.I think the code on the Mega is ok cause i can turn the light on and off many times with PHPwithout problems:

// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etcbyte buttons[] = {14, 15, 16, 17, 18, 19}; // the analog 0-5 pins are also known as 14-19So for the Mega i thought it's "54, 55, 56, 57, 58, 59".And looks like this is correct cause the button (A0) works.

if (justreleased[i]) { justreleased[i] = 0; Serial.print(i, DEC); Serial.println(" Just released"); client.publish("foo/shower","0"); // Turn off Shower Light}I don't get it.And maybe how to make it work with "just pressed" and sending the code just one time.

Can somebody tell me where i have to change the "i" to a button number:

In the square brackets.

Quote

And maybe how to make it work with "just pressed" and sending the code just one time.

If you are having problems with that happening, perhaps you need a sketch that illustrates JUST that problem. I fail to see how all that code dealing with the ethernet class, etc. is related to your problem with the switches.