Advertisement
Guest User

Untitled

a guest
Nov 13th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. // lights and chars match up 1:1, in order
  2. // 0 1 2 3 4 5 6 7 8
  3. int lights[] = {2, 3, 9, 10, 11, A2, A3, A4, A5};
  4.  
  5. // 012345678
  6. char letters[] = "noreghiut";
  7.  
  8. // how long we should wait before restarting the words
  9. int waitBetweenLoops = 15000;
  10. int easterEggCount = 30;
  11.  
  12. // Note that X, Y, and Z are used as indicators that the on and off time needs to change
  13. char wordLetters[] = {"Xeghinortu eghinortu eghinortu eghinortu eghinortuY no right here Zrun"};
  14.  
  15. // --- Final values
  16.  
  17. // each light, one at a time
  18. int offTimeX = 100;
  19. int onTimeX = 320;
  20.  
  21. // timing for the words
  22. int offTimeY = 300;
  23. int onTimeY = 600;
  24.  
  25. // timing for the final 'run'
  26. int offTimeZ = 800;
  27. int onTimeZ = 1700;
  28.  
  29. // ---
  30.  
  31. // init some vars because I don't know if there is GC
  32. // add off and on times, just in case it doesn't get set later (but should get set later provided wordLetters starts with X)
  33. int offTime = 300;
  34. int onTime = 500;
  35. char letter;
  36.  
  37. int lightCount;
  38. int letterCount;
  39.  
  40. // counting the number of loops, for the easter egg
  41. int loopCount;
  42.  
  43. void setup() {
  44. lightCount = sizeof(lights);
  45. letterCount = sizeof(wordLetters);
  46. loopCount = 0;
  47.  
  48. // init lights
  49. for (int x = 0; x < lightCount; x++) {
  50. pinMode(lights[x], OUTPUT);
  51. }
  52. }
  53.  
  54. // Finds the letter code assoicated with the letter (so we can map to a light)
  55. int getLetterCode(char letter) {
  56. int off = 0;
  57. for (int i = 0; i < lightCount; i++) {
  58. if (letter == letters[i]) {
  59. off = lights[i];
  60. break;
  61. }
  62. }
  63. return off;
  64. }
  65.  
  66. // Activate one light for the given on and off time
  67. void activateLight(int theLight, int theOnTime, int theOffTime) {
  68. digitalWrite(theLight, HIGH);
  69. delay(theOnTime);
  70. digitalWrite(theLight, LOW);
  71. delay(theOffTime);
  72. }
  73.  
  74. // Activate all lights for the given on and off time
  75. void activateAllLights(int theOnTime, int theOffTime) {
  76. for (int i = 0; i < lightCount; i++) {
  77. digitalWrite(lights[i], HIGH);
  78. }
  79. delay(theOnTime);
  80. for (int i = 0; i < lightCount; i++) {
  81. digitalWrite(lights[i], LOW);
  82. }
  83. delay(theOffTime);
  84. }
  85.  
  86. void loop() {
  87. // every once in awhile, turn all the lights on
  88. if (loopCount == easterEggCount) {
  89. for (int i = 0; i < 4; i++) {
  90. activateAllLights(300, 100);
  91. }
  92. activateAllLights(4000, 5000);
  93. loopCount = 0;
  94. }
  95.  
  96. for (int x = 0; x < letterCount; x++) {
  97. letter = wordLetters[x];
  98.  
  99. // X, Y, Z are used as indicators of changing the on and off time
  100. if (letter == 'X') {
  101. offTime = offTimeX;
  102. onTime = onTimeX;
  103. } else if (letter == 'Y') {
  104. offTime = offTimeY;
  105. onTime = onTimeY;
  106. } else if (letter == 'Z') {
  107. offTime = offTimeZ;
  108. onTime = onTimeZ;
  109. } else {
  110. int letterCode = getLetterCode(letter);
  111.  
  112. if (letterCode == 0) {
  113. delay(onTime + offTime);
  114. } else {
  115. activateLight(letterCode, onTime, offTime);
  116. }
  117. }
  118. }
  119. loopCount++;
  120. delay(waitBetweenLoops);
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement