Skip to content

Instantly share code, notes, and snippets.

@tagliati
Created March 17, 2012 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tagliati/2064858 to your computer and use it in GitHub Desktop.
Save tagliati/2064858 to your computer and use it in GitHub Desktop.
Binary leds sequency - I Arduino Hack Day [ES]
int pins[] = {13,3,4};
int pin;
int inPin = 7;
int num = 0;
int val = 0;
int led = 0;
int maxnum = 0;
int delaytime = 300;
int pinCount = sizeof(pins);
void setup() {
for(pin = 0;pin < pinCount; pin= pin+1){
pinMode(pins[pin], OUTPUT);
maxnum = maxnum+pow(2,maxnum);
}
pinMode(inPin, INPUT);
}
void loop() {
val = digitalRead (inPin);
if (val == LOW) {
for(pin = 0;pin < pinCount; pin++){
digitalWrite(pins[pin], (num >> pin) % 2);
}
num = (num == maxnum) ? 0 : num+1;
delay (delaytime);
}
}
@m3nd3s
Copy link

m3nd3s commented Mar 17, 2012

Bacana @tagliati, ficou mais limpo com os loops ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment