Created
July 2, 2013 22:35
-
-
Save jonathanperret/5913862 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
void setup() { | |
} | |
int NONE = -1; | |
int actualPins[] = {2, 3, 4}; | |
void set(int pin, int st) { | |
int actualPin = actualPins[pin]; | |
if(st == NONE) { | |
pinMode(actualPin, INPUT); | |
} else { | |
pinMode(actualPin, OUTPUT); | |
digitalWrite(actualPin, st); | |
} | |
} | |
int otherpin(int pin1, int pin2) { | |
return 3 - pin1 - pin2; | |
} | |
void lightpair(int pin1, int pin2) { | |
set(pin1, HIGH); | |
set(pin2, LOW); | |
set(otherpin(pin1, pin2), NONE); | |
} | |
struct Pair { | |
int pin1, pin2; | |
}; | |
Pair pairs[] = { | |
{0,1}, | |
{0,2}, | |
{2,0}, | |
{2,1}, | |
{1,2}, | |
{1,0}, | |
}; | |
float pair = 0.0; | |
int potmin = 300; | |
int potmax = 800; | |
void loop() { | |
int pot = analogRead(0); | |
if(pot < potmin) potmin = pot; | |
if(pot > potmax) potmax = pot; | |
int potmid = (potmin + potmax)/2; | |
float inc = float(pot - potmin) / (potmax - potmin) - 0.5; | |
pair += 0.01 * inc; | |
if(pair<0) pair = 5.99; | |
if(pair>=6) pair = 0.0; | |
lightpair(pairs[(int)pair].pin1, pairs[(int)pair].pin2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment