I plugged 12 switches in my Arduino controller and I need to know which are on and which are off. I am sending this info using Serial.print() Now, I don't want to hog the serial port and send data continuously because that will make the program receiving this data freak out. So I created variables for each switch, and I check whether or not the value changes at every loop() iteration and if it does, I send the new value. Here is the code:

I have a major problem. As soon as I do the whole if (changed) { print() } thing more than 8 times, it stops working. Nothing goes through the serial port. That's why some lines are commented in the code above. Now I know it's not a variable name or hardware problem, because if I comment any other 4 if-statements it still works. As soon as I take out the comments or only comment out 3 statements, nothing gets printed to the serial port.

On top of that, the following code, which prints out all the values without checking if they're changed or not, works perfectly:

It may be that your code is too big for the Arduino chip, even if you don't get an error when you try to upload it. What size is reported when you try to upload? If it's between 6 and 7 KB, you may have a board with a 2 KB bootloader. The IDE expects a 1 KB bootloader when it checks if your code is too big.

If this is indeed the problem, there are a few things you can do. (The 2 KB bootloader were unfortunately burned on some boards as the result of a miscommunication in the development team.) Either change the maximum size for your sketches to 6144 in the Arduino preferences file (http://www.arduino.cc/en/Main/Preferences) or burn a new bootloader onto the board (which requires extra hardware: http://www.arduino.cc/en/Main/Bootloader). Arduino 0005, due out as soon as we finish working out the bugs reported at Ars Electronica will reduce the size of the Arduino libraries, leaving more space for your sketches.

You could make your code smaller by making the code that checks the pins a,b,c,d,e,g,h,o,s and r and sends the value if its changed into a function that you call repeatedly from your main loop so that you do not write what is basically the same block of code 10 times in the chips memory.