Hi Guys,
I am using the standard Moteino to read a custom 17key keypad I made and then transmit the Key pressed to a receiver. Once the receiver receives the code it will drive a relay output. Sounds simple
I have written the code for the Keypad and it works great, all buttons are Identified when pressed.
I am using the keypad.h library for this.
As a test to make sure it would transmit and be received before I went any further I used this simple code on a 1 second delay. It worked great and the receiver board received the commands every second. So I know all my other settings are correct.
if (radio.sendWithRetry(RECEIVER, "H", 1)) //target node Id, message as string or byte array, message length
{
Blink(LED, 40, 3); //blink LED 3 times, 40ms between blinks
Serial.println("Marker C Sent Ack"); Serial.println("Command Transmitted");
}
Here is my Loop function that is not working. When I press the 'H' button it does not transmit.
Is there some rule to say I can not do this within the Switch Case?
If I remove the sendwithretry and put a simple Serial.println("Marker H Pressed"); then it works every time so the Switch condition is working.
But as soon as I put the sendwithretry back in it will not transmit. I am sure I am missing something simple here.
Do I need to call a function from the Switch Condition? I tried that but couldn't get the button pressed to transfer into the function I made correctly.
I also tried a seperate if condition at the end of the Switch Case looking for the Key pressed and then calling the sendwithretry but no luck.
I may not have written this properly as I am still learning.
Can someone please have a look and let me know what I am doing wrong. I am sure it is something simple I have missed.
void loop() {
char key = kpd.getKey();
if (key) // Check for a valid key.
{
switch (key)
{
case 'H':
if (radio.sendWithRetry(RECEIVER, "H", 1)) //target node Id, message as string or byte array, message length
{
Blink(LED, 40, 3); //blink LED 3 times, 40ms between blinks
Serial.println("Marker C Sent Ack"); Serial.println("Command Transmitted");
}
break;
case 'C':
if (radio.sendWithRetry(RECEIVER, "C", 1)) //target node Id, message as string or byte array, message length
{
Blink(LED, 40, 3); //blink LED 3 times, 40ms between blinks
Serial.println("Marker C Sent Ack"); Serial.println("Command Transmitted");
}
break;
default:
Serial.println(key); Serial.println(" Transmitted");
}
}
}
UPTDATED: TomWS: enclosed in code blocks