Created
March 17, 2012 20:08
-
-
Save tagliati/2064858 to your computer and use it in GitHub Desktop.
Binary leds sequency - I Arduino Hack Day [ES]
This file contains hidden or 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
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bacana @tagliati, ficou mais limpo com os loops ;)