/*
Example code for DollyShield pushbutton reading
For use with the Arduino IDE or libraries.
(c) 2010 C.A. Church
Licensed under GPLv3
*/
// digital pin # for button
#define BT_PIN_D 14
// range threshold
#define BT_THRESH 70
// num buttons
#define BT_NUM 5
int buttons[5] = {70, 250, 450, 655, 830};
int bt_range[5][2];
void setup() {
pinMode(BT_PIN_D, INPUT);
digitalWrite(BT_PIN_D, HIGH);
Serial.begin(19200);
// setup pushbutton lookup table
for (byte i = 0; i < BT_NUM; i++) {
bt_range[i][0] = buttons[i] - BT_THRESH;
bt_range[i][1] = buttons[i] + BT_THRESH;
}
}
void loop() {
byte button = get_button();
if( button ) {
Serial.print("Pressed Button: ");
Serial.println(button, DEC);
}
delay(200);
}
byte get_button() {
// returns button pressed
// 1-5 for pushbuttons
// 0 for no button pressed
// need analog pin # for analogRead