Created
April 11, 2012 17:08
-
-
Save silviopaganini/2360603 to your computer and use it in GitHub Desktop.
Sequential Lights Arduino
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
/** | |
silvio paganini | s2paganini.com | |
@silviopaganini | |
**/ | |
const int pins[] = {11, 10, 9, 6, 5, 3}; | |
int SIZE = 6; | |
void setup() | |
{ | |
Serial.begin(9600); | |
setPinMode(); | |
} | |
void loop() | |
{ | |
int p = analogRead(0); | |
int a = 1023 / SIZE; | |
for(int i = 0; i<SIZE; i++) | |
{ | |
int l = (a * (i + 1)) - p; | |
if(l < 0) l = 0; | |
if(l > 255) l = 255; | |
analogWrite(pins[i], l); | |
} | |
} | |
void setPinMode() | |
{ | |
for(int i = 0; i<SIZE; i++) | |
{ | |
pinMode(pins[i], OUTPUT); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment