Skip to content

Instantly share code, notes, and snippets.

@silviopaganini
Created April 11, 2012 17:08
Show Gist options
  • Save silviopaganini/2360603 to your computer and use it in GitHub Desktop.
Save silviopaganini/2360603 to your computer and use it in GitHub Desktop.
Sequential Lights Arduino
/**
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