Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- switch (recognition.recognizedIndex)
- {
- case 1:
- // start timer with a duration of one minute in milliseconds
- startTimer(60000);
- break;
- case 2:
- // start timer with a duration of two minutes in milliseconds
- startTimer(120000);
- break;
- case 3:
- // start timer with a duration of five minutes in milliseconds
- startTimer(300000);
- break;
- }
- // start drops at the top of each column - i.e. x = 0
- xPosition[y] = 0;
- // clear column stacks
- columnFull[y] = false;
- stackRow[y] = 8;
- // randomly generate the drop rate for each column
- // and set the timer
- dropRate[y] = random(minRate, maxRate);
- dropTimer[y] = millis() + dropRate[y];
- // randomly generate a drop color for each column
- xColor[y] = random(0xFFFFFF);
- // iterate through each column
- for (y = 0; y < 8; y++)
- {
- // check if the column is already full
- if (columnFull[y] == false)
- {
- // since the column isn't full
- // check if it's time to move the drop
- if (millis() > dropTimer[y])
- {
- // since it's time to move the drop
- // check if the drop has reached the top of the stack
- if (xPosition[y] == stackRow[y])
- {
- // since the drop has reached the top of the stack
- // check if it's time to stack the droplet
- if (millis() > stackTimer)
- {
- // it's time to stack the drop
- // so don't turn it off
- // move the stack row up the column
- stackRow[y] = stackRow[y] - 1;
- // record the color of the drop when it is stacked
- lastColor[stackRow[y]][y] = xColor[y];
- // restart the stack timer
- stackTimer = stackTimer + stackRate;
- // check if the column is full
- if (stackRow[y] == 0)
- {
- // since the column is full
- // set columnFull to true
- // and increment the number of full columns
- columnFull[y] = true;
- fullCount++;
- }
- }
- else
- {
- // drop has reached the top of the stack
- // but it's not time to stack the drop
- // so just 'turn off' the drop
- // and display the LEDs which have just been set
- matrix.setColor(convertRowCol(lastOn[y], y), 0, 0, 0);
- matrix.show();
- }
- // restart the drop at the top
- xPosition[y] = 0;
- // generate a new drop rate for the column
- dropRate[y] = random(minRate, maxRate);
- // generate a new color for the column
- xColor[y] = random(0xFFFFFF);
- }
- else
- {
- // the drop has not reached the top of the stack
- // check if drop is at the top of the column
- if (xPosition[y] != 0)
- {
- // drop is not at the top of the column
- // so turn off the last drop
- matrix.setColor(convertRowCol(lastOn[y], y), 0, 0, 0);
- }
- // turn on the current drop
- matrix.setColor(convertRowCol(xPosition[y], y), xColor[y]);
- // display the LEDs which have just been set
- matrix.show();
- // remember position of current drop
- lastOn[y] = xPosition[y];
- // increment the x position for the next drop within the column
- xPosition[y]++;
- }
- // restart the drop timer
- dropTimer[y] = millis() + dropRate[y];
- }
- }
- }
- // iterate through the rows
- for (x = 0; x < 8; x++)
- {
- // iterate through the columns
- for (y = 0; y < 8; y++)
- {
- // turn on each drop using its last color
- matrix.setColor(convertRowCol(x, y), lastColor[x][y]);
- }
- }
- // display the LEDs which have just been set
- matrix.show();
- // turn on the buzzer
- // at a frequency roughly equivalent to G6
- tone(buzzerPin, 1568);
- // wait 1.5 seconds
- delay(1500);
- // clear all the LEDs
- // and show the blank matrix
- matrix.clear();
- matrix.show();
- // turn off the buzzer
- noTone(buzzerPin);
- // wait 1.5 seconds
- delay(1500);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement