-
-
Save chrwei/0f008e922d04369f39b283c91912ddb5 to your computer and use it in GitHub Desktop.
Bright Ideas 2017 Arduino code
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 pos = 0, dir = 1; // Position, direction of "eye" | |
| unsigned long lastMillis = 0; | |
| int leds[] = {3,5,6,9,10,11}; | |
| #define NUMBER_OF_LEDS (sizeof(leds)/sizeof(int)) | |
| void setup(){ | |
| //configure LED outputs and turn them off | |
| for(int i=0; i < NUMBER_OF_LEDS; i++) { | |
| pinMode(leds[i], OUTPUT); | |
| digitalWrite(leds[i], LOW); | |
| } | |
| pinMode(2, INPUT_PULLUP); | |
| } | |
| void loop(){ | |
| if (lastMillis + 150 <= millis() && digitalRead(2) == HIGH) { | |
| pos += dir; | |
| if(pos == -2) { | |
| dir = -dir; | |
| } else if(pos == NUMBER_OF_LEDS+1) { | |
| dir = -dir; | |
| } | |
| for(int i=0; i < NUMBER_OF_LEDS; i++) { | |
| if(i==pos-1 || i==pos+1) { | |
| analogWrite(leds[i], 16); | |
| } else if(i==pos) { | |
| analogWrite(leds[i], 255); | |
| } else { | |
| digitalWrite(leds[i], LOW); | |
| } | |
| } | |
| lastMillis = millis(); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment