Skip to content

Instantly share code, notes, and snippets.

@dz0ny

dz0ny/msev.cpp Secret

Last active October 20, 2015 06:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dz0ny/09a0b51eae648c1ca984 to your computer and use it in GitHub Desktop.
Save dz0ny/09a0b51eae648c1ca984 to your computer and use it in GitHub Desktop.
#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