added asynchronous timer
This commit is contained in:
parent
53879d6546
commit
62666ebb8c
6 changed files with 608 additions and 505 deletions
|
|
@ -1,21 +1,17 @@
|
|||
// WIP. 3/28/2022: added test state machine. Need to re-write moving to next state
|
||||
// WIP. 4/4/2022: started to implement delay timer asyncronously using existing timer2 interrupt.
|
||||
|
||||
#include "config.h"
|
||||
#include "cubeplex.h"
|
||||
#include <timer.h>
|
||||
|
||||
Timer animationDelay;
|
||||
bool animationDelayTiming = false;
|
||||
|
||||
int color = red;
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("start program...");
|
||||
initCube();
|
||||
timerInit();
|
||||
|
||||
//timerInit();
|
||||
|
||||
currentState = CHASETHEDOT;
|
||||
lastState = -1;
|
||||
|
||||
|
|
@ -29,13 +25,14 @@ void loop() {
|
|||
|
||||
case CHASETHEDOT:
|
||||
chaseTheDot();
|
||||
//currentState = PLANARFLOP3D;
|
||||
break;
|
||||
|
||||
case RANDOMRAINBOW:
|
||||
rainbow_random();
|
||||
break;
|
||||
|
||||
case PLANARFLOP3D:
|
||||
planarFlop3D();
|
||||
//currentState = CHASETHEDOT;
|
||||
break;
|
||||
}
|
||||
animationDelay.update();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
/******************************** CHASE THE DOT *******************************\
|
||||
/******************************** CHASE THE DOT *******************************\
|
||||
| A single point of light moves around the cube randomly and changes colors |
|
||||
| when it tries to go out of bounds |
|
||||
| |
|
||||
| Inspired By: Jonah Glick |
|
||||
| Written By: Asher Glick |
|
||||
| |
|
||||
| Modified By: S. Dugre to use asynchronous timer |
|
||||
\******************************************************************************/
|
||||
|
||||
int xpos = 0;
|
||||
|
|
@ -13,21 +15,23 @@ int zpos = 0;
|
|||
int animationSpeed = 100;
|
||||
|
||||
void chaseTheDot() {
|
||||
//continuePattern = true;
|
||||
|
||||
if (currentState != lastState) {
|
||||
|
||||
lastState = currentState;
|
||||
Serial.print("last State = ");
|
||||
Serial.println(lastState);
|
||||
Serial.print("New State = ");
|
||||
Serial.println(currentState);
|
||||
xpos = 0;
|
||||
ypos = 0;
|
||||
zpos = 0;
|
||||
|
||||
currentTimer = 0;
|
||||
maxTimer = 6250; // 100 ms
|
||||
}
|
||||
|
||||
|
||||
//while (continuePattern) {
|
||||
if ( not animationDelayTiming) {
|
||||
if ( timerReset) {
|
||||
switch (random(0, 6)) {
|
||||
case 0:
|
||||
if (xpos > 0) {
|
||||
|
|
@ -75,8 +79,12 @@ void chaseTheDot() {
|
|||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
animationDelay.start();
|
||||
animationDelayTiming = true;
|
||||
Serial.println("start timer");
|
||||
|
||||
//animationDelay.start();
|
||||
//animationDelayTiming = true;
|
||||
//Serial.println("start timer");
|
||||
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3
config.h
3
config.h
|
|
@ -3,7 +3,10 @@
|
|||
|
||||
typedef enum STATE {
|
||||
CHASETHEDOT,
|
||||
RANDOMRAINBOW,
|
||||
PLANARFLOP3D
|
||||
};
|
||||
|
||||
STATE currentState, lastState;
|
||||
|
||||
bool timerReset = true;
|
||||
|
|
|
|||
848
cubeplex.h
848
cubeplex.h
File diff suppressed because it is too large
Load diff
218
planarFlop3D.ino
218
planarFlop3D.ino
|
|
@ -1,91 +1,159 @@
|
|||
/******************************* PLANAR FLOP 3D *******************************\
|
||||
| Version 2 of the planar flop, doing more complicated maths and 3D vectors |
|
||||
| 'n stuff. Making this function found the bug of reversed z axis line drawing |
|
||||
| |
|
||||
| Modified By: S. Dugre to use asynchronous timer |
|
||||
\******************************************************************************/
|
||||
|
||||
int planarCase;
|
||||
|
||||
void planarFlop3D() {
|
||||
continuePattern = true;
|
||||
int animationSpeed = 50;
|
||||
while (continuePattern) {
|
||||
|
||||
for (int y = 3; y > 0; y--) {
|
||||
for (int z = 0; z < 4; z++) drawLine(color, 0, 3, z, 3, y, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
for (int x = 3; x > 0; x--) {
|
||||
for (int z = 0; z < 4; z++) drawLine(color, 0, 3, z, x, 0, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
if (currentState != lastState) {
|
||||
|
||||
lastState = currentState;
|
||||
Serial.print("New State = ");
|
||||
Serial.println(currentState);
|
||||
|
||||
currentTimer = 0;
|
||||
maxTimer = 3125; // 50 ms
|
||||
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int y = 0; y < 4; y++) drawLine(color, 0, y, 0, x, y, 3);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
for (int z = 3; z > 0; z--) {
|
||||
for (int y = 0; y < 4; y++) drawLine(color, 0, y, 0, 3, y, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
planarCase = 0;
|
||||
}
|
||||
|
||||
for (int z = 0; z < 3; z++) {
|
||||
for (int x = 0; x < 4; x++) drawLine(color, x, 0, 0, x, 3, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
for (int y = 3; y > 0; y--) {
|
||||
for (int x = 0; x < 4; x++) drawLine(color, x, 0, 0, x, y, 3);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
if (timerReset) {
|
||||
switch (planarCase) {
|
||||
case 0:
|
||||
for (int y = 3; y > 0; y--) {
|
||||
for (int z = 0; z < 4; z++) drawLine(color, 0, 3, z, 3, y, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase++;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
|
||||
for (int y = 0; y < 3; y++) {
|
||||
for (int z = 0; z < 4; z++) drawLine(color, 3, 0, z, 0, y, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int z = 0; z < 4; z++) drawLine(color, 3, 0, z, x, 3, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
case 1:
|
||||
for (int x = 3; x > 0; x--) {
|
||||
for (int z = 0; z < 4; z++) drawLine(color, 0, 3, z, x, 0, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase++;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
|
||||
for (int x = 3; x > 0; x--) {
|
||||
for (int y = 0; y < 4; y++) drawLine(color, 3, y, 3, x, y, 0);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
for (int z = 0; z < 3; z++) {
|
||||
for (int y = 0; y < 4; y++) drawLine(color, 3, y, 3, 0, y, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
case 2:
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int y = 0; y < 4; y++) drawLine(color, 0, y, 0, x, y, 3);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase++;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
|
||||
for (int z = 3; z > 0; z--) {
|
||||
for (int x = 0; x < 4; x++) drawLine(color, x, 3, 3, x, 0, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
for (int y = 0; y < 3; y++) {
|
||||
for (int x = 0; x < 4; x++) drawLine(color, x, 3, 3, x, y, 0);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(animationSpeed);
|
||||
}
|
||||
case 3:
|
||||
for (int z = 3; z > 0; z--) {
|
||||
for (int y = 0; y < 4; y++) drawLine(color, 0, y, 0, 3, y, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase++;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
|
||||
case 4:
|
||||
for (int z = 0; z < 3; z++) {
|
||||
for (int x = 0; x < 4; x++) drawLine(color, x, 0, 0, x, 3, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase++;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
|
||||
case 5:
|
||||
for (int y = 3; y > 0; y--) {
|
||||
for (int x = 0; x < 4; x++) drawLine(color, x, 0, 0, x, y, 3);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase++;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
|
||||
case 6:
|
||||
for (int y = 0; y < 3; y++) {
|
||||
for (int z = 0; z < 4; z++) drawLine(color, 3, 0, z, 0, y, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase++;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
|
||||
case 7:
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int z = 0; z < 4; z++) drawLine(color, 3, 0, z, x, 3, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase++;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
|
||||
case 8:
|
||||
for (int x = 3; x > 0; x--) {
|
||||
for (int y = 0; y < 4; y++) drawLine(color, 3, y, 3, x, y, 0);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase++;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
case 9:
|
||||
for (int z = 0; z < 3; z++) {
|
||||
for (int y = 0; y < 4; y++) drawLine(color, 3, y, 3, 0, y, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase++;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
|
||||
case 10:
|
||||
for (int z = 3; z > 0; z--) {
|
||||
for (int x = 0; x < 4; x++) drawLine(color, x, 3, 3, x, 0, z);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase++;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
|
||||
case 11:
|
||||
for (int y = 0; y < 3; y++) {
|
||||
for (int x = 0; x < 4; x++) drawLine(color, x, 3, 3, x, y, 0);
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
//delay(animationSpeed);
|
||||
planarCase = 0;
|
||||
currentTimer = 0;
|
||||
timerReset = false;
|
||||
}
|
||||
color = nextColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
|
||||
/*
|
||||
void timerInit() {
|
||||
animationDelay.setTimeout(100);
|
||||
animationDelay.setCallback(animationDelayCallback);
|
||||
|
|
@ -9,3 +9,4 @@ void animationDelayCallback() {
|
|||
animationDelayTiming = false;
|
||||
//Serial.println("timed out");
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue