hackathon

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit a87b4ec4060ad7500452eb5662c62ce31417f110
parent 1d840b7c2d99a1ec845c1fe4ff024f113856f486
Author: thing1 <thing1@seacrossedlovers.xyz>
Date:   Sun,  3 May 2026 16:09:42 +0100

piano!

Diffstat:
Rbad-apple.c -> badapple/bad-apple.c | 0
Rbad-apple/bad-apple.ino -> badapple/bad-apple/bad-apple.ino | 0
Rbad-apple/tones.h -> badapple/bad-apple/tones.h | 0
Rconvert.py -> badapple/convert.py | 0
Abadapple/gen | 0
Rtones.h -> badapple/tones.h | 0
Apiano/piano.ino | 164+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rbad-apple/tones.h -> piano/tones.h | 0
8 files changed, 164 insertions(+), 0 deletions(-)

diff --git a/bad-apple.c b/badapple/bad-apple.c diff --git a/bad-apple/bad-apple.ino b/badapple/bad-apple/bad-apple.ino diff --git a/bad-apple/tones.h b/badapple/bad-apple/tones.h diff --git a/convert.py b/badapple/convert.py diff --git a/badapple/gen b/badapple/gen Binary files differ. diff --git a/tones.h b/badapple/tones.h diff --git a/piano/piano.ino b/piano/piano.ino @@ -0,0 +1,164 @@ +#include <XPT2046_Touchscreen.h> +#include <TFT_eSPI.h> + +#include "tones.h" + +#define SIZE(arr) (sizeof(arr) / sizeof(arr[0])) + +#define XPT2046_IRQ 36 +#define XPT2046_MOSI 32 +#define XPT2046_MISO 39 +#define XPT2046_CLK 25 +#define XPT2046_CS 33 + +#define BG (~(249 << 11) + ~(194 << 5) + ~43) + + +uint32_t timer = 0; +uint8_t note = 0; +uint8_t song[] = { + 1, 3, 2, 1, + 1, 3, 2, 1, + 1, 2, 3, 4, + 1, 2, 3, 4, +}; + +TFT_eSPI tft = TFT_eSPI(); +SPIClass mySpi = SPIClass(VSPI); +XPT2046_Touchscreen ts(XPT2046_CS, XPT2046_IRQ); + +void setup() { + mySpi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS); + + ts.begin(mySpi); + ts.setRotation(1); + + tft.init(); + tft.setRotation(1); + + tft.fillScreen(BG); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + + int width = (tft.width() / 7); + for (int i = 0; i < 7; i++) + //tft.fillRect(width * i + 3, 150, width - 6, 90, ~TFT_WHITE); + tft.fillSmoothRoundRect(width * i + 3, 150, width - 6, 90, 10, ~TFT_WHITE); + + for (int i = 0; i < 7; i++) { + switch (i) { + case 0: case 1: case 3: case 4: case 5: + //tft.fillRect(width * i + width * 0.75, 150, width / 2, 60, ~TFT_BLACK); + tft.fillSmoothRoundRect(width * i + width * 0.75, 150, width / 2, 60, 10, ~TFT_BLACK); + break; + } + } +} + +void drawBg() { + tft.fillRect(0, 0, tft.width(), 150, BG); +} + +void playTone(TS_Point *p) { + noTone(26); + if (p->y < 2000) + return; + + int width = 3800 / 7; + if (p->y > 2000 && p->y < 3350) { + for (int i = 0; i < 7; i++) { + if (p->x > width * i + width * 0.75 && p->x < width * i + width * 0.75 + width / 2) { + switch (i) { + case 0: + tone(26, NOTE_CS4, 100); + return; + case 1: + tone(26, NOTE_DS4, 100); + return; + case 3: + tone(26, NOTE_FS4, 100); + return; + case 4: + tone(26, NOTE_GS4, 100); + return; + case 5: + tone(26, NOTE_AS4, 100); + return; + } + } + } + } + + if (p->x < width) + tone(26, NOTE_C4, 100); + else if (p->x < width * 2) + tone(26, NOTE_D4, 100); + else if (p->x < width * 3) + tone(26, NOTE_E4, 100); + else if (p->x < width * 4) + tone(26, NOTE_F4, 100); + else if (p->x < width * 5) + tone(26, NOTE_G4, 100); + else if (p->x < width * 6) + tone(26, NOTE_A4, 100); + else if (p->x < width * 7) + tone(26, NOTE_B4, 100); +} + +int getNote(TS_Point *p) { + noTone(26); + if (p->y < 2000) + return -1; + + int width = 3800 / 7; + + if (p->x < width) + return 0; + else if (p->x < width * 2) + return 1; + else if (p->x < width * 3) + return 2; + else if (p->x < width * 4) + return 3; + else if (p->x < width * 5) + return 4; + else if (p->x < width * 6) + return 5; + else if (p->x < width * 7) + return 6; +} + +void loop() { + static int i; + + if (ts.tirqTouched() && ts.touched()) { + TS_Point p = ts.getPoint(); + playTone(&p); + if (getNote(&p) == song[note]) { + if (timer > 100) { + note++; + timer = 0; + } + } + } + + if (timer % 10) { + drawBg(); + } + + if (note < SIZE(song)) { + int width = (tft.width() / 7); + + if (++i % 4) + timer++; + tft.fillRect(song[note] * width, timer, width, 30, ~TFT_BLACK); + + if (timer > 150 - 30) { + timer = 0; + tft.println("YOU LOOSE"); + while (1) continue; + } + } else { + tft.println("YOU WIN"); + while (1) continue; + } +} diff --git a/bad-apple/tones.h b/piano/tones.h