Created
June 15, 2015 21:38
-
-
Save malcolmocean/6730ba2c36d43b7c5bf9 to your computer and use it in GitHub Desktop.
Source code for making the word "Arduino" show up when you move 10 LEDs past very quickly
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
/* .-----------------, | |
* / Text on 10 LEDs \ | |
* | malcolmocean.com | | |
* \ Malcolm Ocean / | |
* `-----------------' | |
* | |
* For a description of how this code is used, see: | |
* http://malcolmocean.com/2011/11/arduino-text-on-leds/ | |
* | |
* Uses a modifed version of the circuit at http://tinyurl.com/d2hrud | |
* Really, all you need is 10 LEDs in a line. | |
* | |
*/ | |
int ledPins[] = {2,3,4,5,6,7,8,9,10,11}; | |
int cols = 54; | |
int rows = 10; | |
int c = 0; | |
int r = 0; | |
int framerate = 3; | |
int oldpattern[10][20] = {{0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, | |
{0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0}, | |
{0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0}, | |
{0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0}, | |
{1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0}, | |
{1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0}, | |
{0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0}, | |
{0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0}, | |
{0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0}, | |
{0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; | |
int pattern[10][74] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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|
void setup() { | |
for(int i = 0; i < 10; i++) { | |
pinMode(ledPins[i],OUTPUT); | |
} | |
} | |
void loop() { | |
for(int r = 0; r < rows; r++) { | |
digitalWrite(ledPins[r], binToDigital(pattern[r][c])); | |
} | |
// go to next column or beginning | |
c = (c == cols-1) ? 0 : c+1; | |
delay(c==0 ? 1000 : framerate); // delay briefly. if at end of sequence, delay for 1s. | |
} | |
int binToDigital (int bin) { | |
return bin == 1 ? HIGH : LOW; | |
} | |
// Random | |
void randomize() { | |
int rint = random(rows); | |
digitalWrite(ledPins[rint], !digitalRead(ledPins[rint])); | |
delay(16); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment