Last active
October 2, 2017 03:31
-
-
Save epylinkn/92717f490f74c9439f5272be9eff12b3 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
int led_pin = 8; | |
int switch_pin = 9; | |
int pot_pin_1 = A1; | |
int pot_pin_2 = A2; | |
int pot_pin_3 = A3; | |
int last_switch_state = LOW; | |
void setup() { | |
pinMode(led_pin, OUTPUT); | |
pinMode(pot_pin_1, INPUT); | |
pinMode(pot_pin_2, INPUT); | |
pinMode(pot_pin_3, INPUT); | |
pinMode(switch_pin, INPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
int pot_one_reading = analogRead(pot_pin_1); | |
delay(1); | |
int pot_two_reading = analogRead(pot_pin_2); | |
delay(1); | |
int pot_three_reading = analogRead(pot_pin_3); | |
delay(1); | |
int switch_reading = digitalRead(switch_pin); | |
// Potentiomenter position mapped to 0-9 digits | |
int pot_one_digit = map(pot_one_reading, 0, 1024, 0, 10); | |
int pot_two_digit = map(pot_two_reading, 0, 1024, 0, 10); | |
int pot_three_digit = map(pot_three_reading, 0, 1024, 0, 10); | |
Serial.print("\t"); | |
Serial.print(pot_one_digit); | |
Serial.print("\t"); | |
Serial.print(pot_two_digit); | |
Serial.print("\t"); | |
Serial.println(pot_three_digit); | |
// Evaluate when switch is pressed | |
if (last_switch_state == LOW && switch_reading != last_switch_state) { | |
if (pot_one_digit == 3 && pot_two_digit == 6 && pot_three_digit == 9) { | |
digitalWrite(led_pin, HIGH); | |
} else { | |
digitalWrite(led_pin, LOW); | |
} | |
} | |
last_switch_state = switch_reading; | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment