/************************************************************************************/
/*
keyboard_getButton()
Return pressed button on "5 Button Arduino Keyboard" form eBay or Aliexpress
NOTE:
- replace R1=220K on WeMos D1 Mini with 470K or you will damege ESP8266!!!
- connect "5 Button Arduino Keyboard" to 3.3V, GND & ADC pin
*/
/************************************************************************************/
uint8_t keyboard_getButton()
{
switch (analogRead(A0)) //write spaces around " ... ", otherwise it may be parsed wrong also see NOTE
{
case 500 ... ADC_STEPS: //idle, Vin=3.3v/606=3.388v or Vin=5.0v/592=5v
return 0;
case 0 ... 20: //station-, Vin=3.3v/0=0.000v or Vin=5.0v/3=0.024v
return 1;
case 40 ... 80: //volume-, Vin=3.3v/58=0.324v or Vin=5.0v/224=1.854v
return 2;
case 140 ... 180: //volume+, Vin=3.3v/162=0.906v or Vin=5.0v/85=0.704v
return 3;
case 260 ... 300: //station+, Vin=3.3v/282=1.577v or Vin=5.0v/386=3.195v
return 4;
case 420 ... 460: //play/pause, Vin=3.3v/437=2.437v or Vin=5.0v/592=4.899v
return 5;
default: //out of range, not a "5 Button Arduino Keyboard"
return 0;
}
}