Skip to content

Instantly share code, notes, and snippets.

@hughrawlinson
Last active February 11, 2016 11:42
Show Gist options
  • Save hughrawlinson/57bc4574c962eda4856a to your computer and use it in GitHub Desktop.
Save hughrawlinson/57bc4574c962eda4856a to your computer and use it in GitHub Desktop.
Binary Counting LEDs
int analogInput = 0;
int rate = 0;
int val = 0;
int count = 0;
void setup()
{
pinMode(analogInput, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
Serial.begin(300);
}
void loop()
{
count++;
count = count % 256;
digitalWrite(2, count%2==1?HIGH:LOW);
digitalWrite(3, count/2%2==1?HIGH:LOW);
digitalWrite(4, count/4%2==1?HIGH:LOW);
digitalWrite(5, count/8%2==1?HIGH:LOW);
digitalWrite(6, count/16%2==1?HIGH:LOW);
digitalWrite(7, count/32%2==1?HIGH:LOW);
digitalWrite(8, count/64%2==1?HIGH:LOW);
digitalWrite(9, count/128%2==1?HIGH:LOW);
val = analogRead(analogInput);
Serial.println(val);
delay(val);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment