Completed Konami puzzle!

This commit is contained in:
Neale Pickett 2020-12-08 21:56:47 -07:00
parent 7c167d218d
commit 5f30ec894f
1 changed files with 47 additions and 12 deletions

View File

@ -121,11 +121,36 @@ CHSV loop_morse(bool fg) {
return color; return color;
} }
#define UP 24
#define DOWN 25
#define RIGHT 26
#define LEFT 27
#define IN 15
#define OUT 9
const char KonamiCode[] = {
UP,
UP,
DOWN,
DOWN,
LEFT,
RIGHT,
LEFT,
RIGHT,
IN,
OUT,
0,
};
CHSV loop_konami(bool fg) { CHSV loop_konami(bool fg) {
static bool solved = false;
static int pos = 0;
static Pulse pulse = Pulse(100); static Pulse pulse = Pulse(100);
CHSV color; CHSV color;
uint8_t gesture; uint8_t gesture;
if (solved) {
return ColorSolved;
}
uint8_t prox = 0; uint8_t prox = 0;
if (!paj7620ReadReg(0x6c, 1, &prox)) { if (!paj7620ReadReg(0x6c, 1, &prox)) {
display.fillRect(0, 0, 84, 4, 0); display.fillRect(0, 0, 84, 4, 0);
@ -145,36 +170,46 @@ CHSV loop_konami(bool fg) {
case 0: case 0:
break; break;
case GES_UP_FLAG: case GES_UP_FLAG:
out = 26; // right out = RIGHT;
break; break;
case GES_DOWN_FLAG: case GES_DOWN_FLAG:
out = 27; // left out = LEFT;
break; break;
case GES_RIGHT_FLAG: case GES_RIGHT_FLAG:
out = 25; // down out = DOWN;
break; break;
case GES_LEFT_FLAG: case GES_LEFT_FLAG:
out = 24; // up out = UP;
break; break;
case GES_FORWARD_FLAG: case GES_FORWARD_FLAG:
out = 15; out = IN;
break; break;
case GES_BACKWARD_FLAG: case GES_BACKWARD_FLAG:
out = 9; out = OUT;
break; break;
default: default:
out = '?'; // out = '?';
display.fillRect(0, 32, 15, 8, 0);
display.setCursor(0, 32);
display.print(gesture);
break; break;
} }
if (out) { if (out) {
display.fillRect(0, 40, 5, 8, 0); if (out == KonamiCode[pos]) {
display.setCursor(0, 40); display.fillRect(pos*6, 40, 6, 8, 0);
display.setCursor(pos * 6, 40);
++pos;
} else {
display.fillRect(0, 40, 84, 8, 0);
display.setCursor(0, 40);
pos = 0;
}
display.print(out); display.print(out);
} }
} }
if (KonamiCode[pos] == 0) {
solved = true;
mp.Play(120 * 4, TUNE_YAY);
color = ColorSolved;
}
display.display(); display.display();
return color; return color;