Is it possible to use the
’
else if(keypad_value < 800)
return ‘S’;
’ button in two different ways,
if i hold the button for 5 seconds it returns an ‘Q’
in this way.
char ReadKeypad()
{
keypad_value = analogRead(keypad_pin);
if(keypad_value < 100)
return ‘R’;
else if(keypad_value < 200)
return ‘U’;
else if(keypad_value < 400)
return ‘D’;
else if(keypad_value < 600)
return ‘L’;
else if(keypad_value < 800)
return ‘S’;
else
return ‘N’;
}
system
#2
Yes; record the time the switch becomes pressed.
If five seconds has eleapsed, and the button is still pressed, send the alternate letter.
char resetbutton=3000;
char count=0;
{
keypad_value = analogRead(keypad_pin);
if(keypad_value < 100)
return ‘R’;
else if(keypad_value < 200)
return ‘U’;
else if(keypad_value < 400)
return ‘D’;
else if(keypad_value < 600)
return ‘L’;
else if(keypad_value < 800)
return ‘S’;
while (keypad_value < 800) count+=1;
if (count>=resetbutton)
return ‘Q’;
else
return ‘N’;
Serial.println(count);
}
this what i have now, what can i do to make it work?
you could try like this, though most would opt for non-blocking methods:
char resetbutton=3000;
char count=0;
{
keypad_value = analogRead(keypad_pin);
if(keypad_value < 100)
return 'R';
else if(keypad_value < 200)
return 'U';
else if(keypad_value < 400)
return 'D';
else if(keypad_value < 600)
return 'L';
else if(keypad_value < 800)
uint32_t startPress = millis();
while(keypad_value < 800 && keypad_value > 600)
{
keypad_value = analogRead(keypad_pin);
}
if(millis() - startPress < 1000UL)
{
return 'S';
}
else
{
return 'Q';
}
else
return 'N';
Serial.println(count);
}