Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // lights and chars match up 1:1, in order
- // 0 1 2 3 4 5 6 7 8
- int lights[] = {2, 3, 9, 10, 11, A2, A3, A4, A5};
- // 012345678
- char letters[] = "noreghiut";
- // how long we should wait before restarting the words
- int waitBetweenLoops = 15000;
- int easterEggCount = 30;
- // Note that X, Y, and Z are used as indicators that the on and off time needs to change
- char wordLetters[] = {"Xeghinortu eghinortu eghinortu eghinortu eghinortuY no right here Zrun"};
- // --- Final values
- // each light, one at a time
- int offTimeX = 100;
- int onTimeX = 320;
- // timing for the words
- int offTimeY = 300;
- int onTimeY = 600;
- // timing for the final 'run'
- int offTimeZ = 800;
- int onTimeZ = 1700;
- // ---
- // init some vars because I don't know if there is GC
- // add off and on times, just in case it doesn't get set later (but should get set later provided wordLetters starts with X)
- int offTime = 300;
- int onTime = 500;
- char letter;
- int lightCount;
- int letterCount;
- // counting the number of loops, for the easter egg
- int loopCount;
- void setup() {
- lightCount = sizeof(lights);
- letterCount = sizeof(wordLetters);
- loopCount = 0;
- // init lights
- for (int x = 0; x < lightCount; x++) {
- pinMode(lights[x], OUTPUT);
- }
- }
- // Finds the letter code assoicated with the letter (so we can map to a light)
- int getLetterCode(char letter) {
- int off = 0;
- for (int i = 0; i < lightCount; i++) {
- if (letter == letters[i]) {
- off = lights[i];
- break;
- }
- }
- return off;
- }
- // Activate one light for the given on and off time
- void activateLight(int theLight, int theOnTime, int theOffTime) {
- digitalWrite(theLight, HIGH);
- delay(theOnTime);
- digitalWrite(theLight, LOW);
- delay(theOffTime);
- }
- // Activate all lights for the given on and off time
- void activateAllLights(int theOnTime, int theOffTime) {
- for (int i = 0; i < lightCount; i++) {
- digitalWrite(lights[i], HIGH);
- }
- delay(theOnTime);
- for (int i = 0; i < lightCount; i++) {
- digitalWrite(lights[i], LOW);
- }
- delay(theOffTime);
- }
- void loop() {
- // every once in awhile, turn all the lights on
- if (loopCount == easterEggCount) {
- for (int i = 0; i < 4; i++) {
- activateAllLights(300, 100);
- }
- activateAllLights(4000, 5000);
- loopCount = 0;
- }
- for (int x = 0; x < letterCount; x++) {
- letter = wordLetters[x];
- // X, Y, Z are used as indicators of changing the on and off time
- if (letter == 'X') {
- offTime = offTimeX;
- onTime = onTimeX;
- } else if (letter == 'Y') {
- offTime = offTimeY;
- onTime = onTimeY;
- } else if (letter == 'Z') {
- offTime = offTimeZ;
- onTime = onTimeZ;
- } else {
- int letterCode = getLetterCode(letter);
- if (letterCode == 0) {
- delay(onTime + offTime);
- } else {
- activateLight(letterCode, onTime, offTime);
- }
- }
- }
- loopCount++;
- delay(waitBetweenLoops);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement