Create a gist now

Instantly share code, notes, and snippets.

@dz0ny /msev.cpp Secret
Last active Oct 20, 2015

What would you like to do?
#define BUTTON_PIN_A0 A0
#define BUTTON_PIN_A1 A1
int previousStateA0;
int previousStateA1;
void setup() {
Serial.begin(9600);
previousState = 0;
}
void loop() {
updateButton(BUTTON_PIN_A0, previousStateA0);
updateButton(BUTTON_PIN_A1, previousStateA1);
}
void updateButton(int pin, int &holder){
int analogValue = analogRead(pin);
int actualState;
if(analogValue < 100) actualState = 1;
else if(analogValue < 900) actualState = 3;
else actualState = 2;
if(*holder != actualState) {
*holder = actualState;
Serial.print("Button state: ");
Serial.println(actualState);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment