ADC Keypad Due+RADDS
I had to make a few changes to the ADC keypad code from CONTROLLER_ZONESTAR and I wanted to see if you thought is would cause any problems (delays, etc) . I'm trying this because I can't get the regular 4x4 matrix to work reliably on my Due+RADDS using any combination of available pins. (I get Phantom/ghost button presses, when no button has been pressed). The 4x4 matrix worked fine on the RAMPS, but I think maybe having 3.2v ref instead of 5v made matrix key press detection problematic.
Basically I just commented out the way it got the value for ADC and replaced it with an analogRead() because I wasn't getting a value from the old code....then I changed the rest of the code to work for the scale of the value I was getting (max of 1023, not 4000).
to see the value for each pressed button I temporarily uncomment out the part that serial prints the ADC value.
inline void uiCheckSlowKeys(uint16_t &action) {
to see the value for each pressed button I temporarily uncomment out the part that serial prints the ADC value.
inline void uiCheckSlowKeys(uint16_t &action) {
struct {
uint16_t min;
uint16_t max;
uint16_t action;
} keys[] = {
{ 0, 15, UI_ACTION_IDENT01 },
{ 160, 180, UI_ACTION_IDENT02 },
{ 302, 322, UI_ACTION_IDENT03 },
{ 417, 437, UI_ACTION_IDENT04 },
{ 510, 530, UI_ACTION_IDENT05 },
{ 590, 610, UI_ACTION_IDENT06 },
{ 655, 675, UI_ACTION_IDENT07 },
{ 715, 735, UI_ACTION_IDENT08 },
{ 765, 785, UI_ACTION_IDENT09 },
{ 811, 831, UI_ACTION_IDENT10 },
{ 850, 870, UI_ACTION_IDENT11 },
{ 885, 902, UI_ACTION_IDENT12 },
{ 915, 935, UI_ACTION_IDENT13 },
{ 945, 965, UI_ACTION_IDENT14 },
{ 971, 991, UI_ACTION_IDENT15 },
{ 999, 1015, UI_ACTION_IDENT16 }
};
const uint8_t numOfKeys = sizeof(keys) / sizeof(keys[0]);
extern volatile uint16_t osAnalogInputValues[ANALOG_INPUTS];
// uint16_t adc = osAnalogInputValues[KEYPAD_ANALOG_INDEX] >> (ANALOG_REDUCE_BITS);
uint16_t adc = analogRead(ADC_KEYPAD_PIN) ;
// if (adc < 4000) {
if (adc < 1016) {
for (int8_t i = 0; i < numOfKeys; ++i) {
if ((adc >= keys[i].min) && (adc < keys[i].max)) {
action = keys[i].action;
// Serial.print("ADC V:") ;
// Serial.println(adc);
return;
} else {
// Serial.print("ADC X:") ;
// Serial.println(adc);
}
}
}
}
Comments
temp4 pin is only ok if it is a thermocouple pin, normal temperature pins have a 4.7k resistor connected to pin so changing the result.
uint16_t adc = osAnalogInputValues[KEYPAD_ANALOG_INDEX] >> (ANALOG_REDUCE_BITS);
doesn't give me a value if I:
Serial.println(adc);
also, if I use the ADC_KEYPAD_PIN with analogread() I get strange values starting off with a solid 781 until you hit the buttons on the keypad for a while. So when I hook my ADC keypad up to the temp pin instead I get a solid 1023 right off the bat with analogread() and all my key presses come up with consistent values (also with analogread() )
if analogread() will break other readings then thats the sort of thing I was worried about. what do I need to do to get this working?:
uint16_t adc = osAnalogInputValues[KEYPAD_ANALOG_INDEX] >> (ANALOG_REDUCE_BITS);
I suppose I could be getting a reading that Serial.print might not be able to display, but if that is the case then I wont know what values to map to my key presses.