Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. switch (recognition.recognizedIndex)
  2.  
  3. {
  4.  
  5. case 1:
  6.  
  7. // start timer with a duration of one minute in milliseconds
  8.  
  9. startTimer(60000);
  10.  
  11. break;
  12.  
  13. case 2:
  14.  
  15. // start timer with a duration of two minutes in milliseconds
  16.  
  17. startTimer(120000);
  18.  
  19. break;
  20.  
  21. case 3:
  22.  
  23. // start timer with a duration of five minutes in milliseconds
  24.  
  25. startTimer(300000);
  26.  
  27. break;
  28.  
  29. }
  30.  
  31. // start drops at the top of each column - i.e. x = 0
  32.  
  33. xPosition[y] = 0;
  34.  
  35.  
  36.  
  37. // clear column stacks
  38.  
  39. columnFull[y] = false;
  40.  
  41. stackRow[y] = 8;
  42.  
  43.  
  44.  
  45. // randomly generate the drop rate for each column
  46.  
  47. // and set the timer
  48.  
  49. dropRate[y] = random(minRate, maxRate);
  50.  
  51. dropTimer[y] = millis() + dropRate[y];
  52.  
  53.  
  54.  
  55. // randomly generate a drop color for each column
  56.  
  57. xColor[y] = random(0xFFFFFF);
  58.  
  59. // iterate through each column
  60.  
  61. for (y = 0; y < 8; y++)
  62.  
  63. {
  64.  
  65. // check if the column is already full
  66.  
  67. if (columnFull[y] == false)
  68.  
  69. {
  70.  
  71. // since the column isn't full
  72.  
  73. // check if it's time to move the drop
  74.  
  75. if (millis() > dropTimer[y])
  76.  
  77. {
  78.  
  79. // since it's time to move the drop
  80.  
  81. // check if the drop has reached the top of the stack
  82.  
  83. if (xPosition[y] == stackRow[y])
  84.  
  85. {
  86.  
  87. // since the drop has reached the top of the stack
  88.  
  89. // check if it's time to stack the droplet
  90.  
  91. if (millis() > stackTimer)
  92.  
  93. {
  94.  
  95. // it's time to stack the drop
  96.  
  97. // so don't turn it off
  98.  
  99. // move the stack row up the column
  100.  
  101. stackRow[y] = stackRow[y] - 1;
  102.  
  103.  
  104.  
  105. // record the color of the drop when it is stacked
  106.  
  107. lastColor[stackRow[y]][y] = xColor[y];
  108.  
  109.  
  110.  
  111. // restart the stack timer
  112.  
  113. stackTimer = stackTimer + stackRate;
  114.  
  115.  
  116.  
  117. // check if the column is full
  118.  
  119. if (stackRow[y] == 0)
  120.  
  121. {
  122.  
  123. // since the column is full
  124.  
  125. // set columnFull to true
  126.  
  127. // and increment the number of full columns
  128.  
  129. columnFull[y] = true;
  130.  
  131. fullCount++;
  132.  
  133. }
  134.  
  135. }
  136.  
  137. else
  138.  
  139. {
  140.  
  141. // drop has reached the top of the stack
  142.  
  143. // but it's not time to stack the drop
  144.  
  145. // so just 'turn off' the drop
  146.  
  147. // and display the LEDs which have just been set
  148.  
  149. matrix.setColor(convertRowCol(lastOn[y], y), 0, 0, 0);
  150.  
  151. matrix.show();
  152.  
  153. }
  154.  
  155.  
  156.  
  157. // restart the drop at the top
  158.  
  159. xPosition[y] = 0;
  160.  
  161.  
  162.  
  163. // generate a new drop rate for the column
  164.  
  165. dropRate[y] = random(minRate, maxRate);
  166.  
  167.  
  168.  
  169. // generate a new color for the column
  170.  
  171. xColor[y] = random(0xFFFFFF);
  172.  
  173. }
  174.  
  175. else
  176.  
  177. {
  178.  
  179. // the drop has not reached the top of the stack
  180.  
  181. // check if drop is at the top of the column
  182.  
  183. if (xPosition[y] != 0)
  184.  
  185. {
  186.  
  187. // drop is not at the top of the column
  188.  
  189. // so turn off the last drop
  190.  
  191. matrix.setColor(convertRowCol(lastOn[y], y), 0, 0, 0);
  192.  
  193. }
  194.  
  195.  
  196.  
  197. // turn on the current drop
  198.  
  199. matrix.setColor(convertRowCol(xPosition[y], y), xColor[y]);
  200.  
  201.  
  202.  
  203. // display the LEDs which have just been set
  204.  
  205. matrix.show();
  206.  
  207.  
  208.  
  209. // remember position of current drop
  210.  
  211. lastOn[y] = xPosition[y];
  212.  
  213.  
  214.  
  215. // increment the x position for the next drop within the column
  216.  
  217. xPosition[y]++;
  218.  
  219. }
  220.  
  221.  
  222.  
  223. // restart the drop timer
  224.  
  225. dropTimer[y] = millis() + dropRate[y];
  226.  
  227. }
  228.  
  229. }
  230.  
  231. }
  232.  
  233. // iterate through the rows
  234.  
  235. for (x = 0; x < 8; x++)
  236.  
  237. {
  238.  
  239. // iterate through the columns
  240.  
  241. for (y = 0; y < 8; y++)
  242.  
  243. {
  244.  
  245. // turn on each drop using its last color
  246.  
  247. matrix.setColor(convertRowCol(x, y), lastColor[x][y]);
  248.  
  249. }
  250.  
  251. }
  252.  
  253.  
  254.  
  255. // display the LEDs which have just been set
  256.  
  257. matrix.show();
  258.  
  259.  
  260.  
  261. // turn on the buzzer
  262.  
  263. // at a frequency roughly equivalent to G6
  264.  
  265. tone(buzzerPin, 1568);
  266.  
  267.  
  268.  
  269. // wait 1.5 seconds
  270.  
  271. delay(1500);
  272.  
  273.  
  274.  
  275. // clear all the LEDs
  276.  
  277. // and show the blank matrix
  278.  
  279. matrix.clear();
  280.  
  281. matrix.show();
  282.  
  283.  
  284.  
  285. // turn off the buzzer
  286.  
  287. noTone(buzzerPin);
  288.  
  289.  
  290.  
  291. // wait 1.5 seconds
  292.  
  293. delay(1500);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement