I am in no ways a good code writer. What I have is a wii nunchuck attached to my arduino as well as and LCD attached to the arduino. I have modified the nunchuck library to use button c, z, and the joystick, and return as boolean for all.
The following are boolean:
chuck.zPressed();
chuck.cPressed();
chuck.rightJoy();
chuck.leftJoy();
chuck.upJoy();
chuck.downJoy();
The problem is in my tortuous coding technique
lcd.setCursor(0,0);
if (chuck.cPressed()) {
lcd.print("C");
}
else if (chuck.zPressed()) {
lcd.print("Z");
}
else if (chuck.rightJoy()) {
lcd.print("Right");
}
else if (chuck.leftJoy()) {
lcd.print("Left");
}
else if (chuck.upJoy()) {
lcd.print("Up");
}
else if (chuck.downJoy()) {
lcd.print("Down");
}
else {
lcd.clear();
}
The above works just fine, but it's also possible to have button C, button Z, upJoy, and leftJoy all be true at the same time. In the future, I want to implement combo buttons.
Writing like this is beyond tortuous considering how many combinations there are
if (chuck.cPressed() && chuck.zPressed() && chuck.upJoy() && chuck.leftJoy()) {
lcd.print("C and Z and Up and Left");
}
else if (chuck.zPressed()) {
lcd.print("Z");
}
The number of else if branches would be very long but it would work.
Is there a better method? If not, I'll just do all the combinations.
Lastly, when combo buttons are being pressed, they are not pressed all at the same time. Is there a way for me to say:
if (chuck.cPressed()) {
wait for 1 second to check for more button presses
do stuff
}
I'm sure I will learn alot!
Thank you very much!