-
-
Save dz0ny/09a0b51eae648c1ca984 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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