Questa versione viene buildata, ma ha dei minor issue (inspect-output.txt) notati dal platformio inspector (pio check) che sarebbe meglio sistemare e controllare. Dovrebbe Funzionare ma va testata, nei docs ci sono le info su come funziona ora il codice per fare troubleshooting.

This commit is contained in:
Jasssbo 2025-08-30 15:03:07 +02:00
parent eadf2d7679
commit 194fd2afdc
39 changed files with 4067 additions and 1852 deletions

144
README.md
View file

@ -1,78 +1,108 @@
# TWANG
A Arduino-based, 1D, LED loving, dungeon crawler. inspired by Line Wobbler by Robin B
README - TWANG ESP32
=====================
## Video playlist
A playlist that shows the development of TWANG and the game in both a desktop and house-sized form can be found here: https://www.youtube.com/watch?v=9yf_VINmbTE&list=PL1_Z89_x_Dff-XhOxlx6sQ38wJqe1X2M0
Scopo
-----
## Required libraries:
* FastLED: https://github.com/FastLED/FastLED/files/4608545/FastLED.zip
* I2Cdev
* MPU6050: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050
* RunningMedian: http://playground.arduino.cc/Main/RunningMedian
Repository per il gioco TWANG su ESP32. Ho migrato il controllo LED da FastLED a NeoPixelBus per evitare problemi specifici su ESP32. Questo README spiega come verificare che la build funzioni e come testare la striscia LED e gli input.
## Hardware used:
* Arduino MEGA/NANO
* 3 LEDs for life indicator
* APA102-C LED light strip. The more the better, maximum of 1000. Tested with 2x 144/meter and 12x 60/meter strips. The FastLED lib works with the less expensive WS2812 LEDs, i've not tried them but should be fine.
* 5v power supply, assume around 40mW per LED to calculate size
* MPU6050 accelerometer
* Spring doorstop, I used these: http://smile.amazon.com/gp/product/B00J4Y5BU2
Checklist rapida (stato)
------------------------
## Enclosure
Files to print your own enclosure can be found here: http://www.thingiverse.com/thing:1116899
- Migrazione FastLED -> NeoPixelBus: Done
- Rimozione build flags FastLED: Done
- `LedController` aggiornato per NeoPixelBus: Done
- `GameEngine` aggiornato per usare `RgbColor`: Done
- Correzione `Level::reset` signature: Done
- Build PlatformIO: PASS (firmware generato)
## Overview
TWANG was developed quickly to make my Halloween lights interactive, the code is fairly well commmented but could be improved. The following is a quick overview of the code to help you understand and tweak the game to your needs.
File modificati / aggiunti
-------------------------
The game is played on a 1000 unit line, the position of enemies, the player, lava etc range from 0 to 1000 and the LEDs that represent them are derived using the getLED() function. You don't need to worry about this but it's good to know for things like the width of the attack and player max move speed. Regardles of the number of LEDs, everything takes place in this 1000 unit wide line.
- `platformio.ini` — dipendenza aggiornata a `makuna/NeoPixelBus` e rimozione flags FastLED
- `src/hardware/LedController.h` — nuova implementazione con NeoPixelBus
- `src/game/GameEngine.cpp` — sostituiti i riferimenti `CRGB` -> `RgbColor`
- `src/game/Level.h``reset(Player &p)` ora chiama `p.reset()` senza argomenti
- `docs/CONTROLS.md` — piccola correzione heading
- `README.md` — questo file
**ATMEGA4809**
The TWANG4809 sketch is intended for use with the Arduino Nano Every and the Uno Wifi REV2 both of which use the Atmega 4809 processor.
At the time of writing, these boards do not have out of the box support for FastLED or ToneAC.
This sketch removes the ToneAC functionality.
For FastLED to function, install [this](https://github.com/FastLED/FastLED/files/4608545/FastLED.zip) library instead of the one listed in Arduino IDE.
Come verificare la build (locale)
--------------------------------
**//LED SETUP** Defines the quantity of LEDs as well as the data and clock pins used. I've tested several APA102-C strips and the color order sometimes changes from BGR to GBR or GRB, if the player is not blue, the exit green and the enemies red, this is the bit you want to change. Brightness should range from 50 to 255, use a lower number if playing at night or wanting to use a smaller power supply. "DIRECTION" can be set to 0 or 1 to flip the game orientation. In setup() there is a "FastLED.addLeds()" line, in there you could change it to another brand of LED strip like the cheaper WS2812.
Apri una PowerShell (pwsh) nella cartella del progetto (root dove c'è `platformio.ini`) e lancia:
The game also has 3 regular LEDs for life indicators (the player gets 3 lives which reset each time they level up). The pins for these LEDs are stored in lifeLEDs[] and are updated in the updateLives() function
```powershell
# compilazione
platformio run
**//JOYSTICK SETUP** All parameters are commented in the code, you can set it to work in both forward/backward as well as side-to-side mode by changing JOYSTICK_ORIENTATION. Adjust the ATTACK_THRESHOLD if the "Twanging" is overly sensitive and the JOYSTICK_DEADZONE if the player slowly drifts when there is no input (because it's hard to get the MPU6050 dead level).
# upload (se la board è collegata e vuoi flashare)
platformio run --target upload
**//WOBBLE ATTACK** Sets the width, duration (ms) of the attack.
# apertura seriale per test realtime (115200)
platformio device monitor --baud 115200
```
**//POOLS** These are the object pools for enemies, particles, lava, conveyors etc. You can modify the quantity of any of them if your levels use more or if you want to save some memory, just remember to update the respective counts to avoid errors.
Cosa controllare dopo la build
-----------------------------
**//USE_GRAVITY** 0/1 to set if particles created by the player getting killed should fall towards the start point, the BEND_POINT variable can be set to mark the point at which the strip of LEDs goes from been horizontal to vertical. The game is 1000 units wide (regardless of number of LED's) so 500 would be the mid point. If this is confusing just set USE_GRAVITY to 0.
1. `platformio run` termina con "SUCCESS" e viene generato `firmware.bin`.
2. Non devono comparire errori di link o simboli non definiti.
3. Se vuoi verificare comportamento LED prima di caricare, puoi comunque aprire il serial monitor e inviare comandi (vedi sotto).
## Modifying / Creating levels
Find the loadLevel() function, in there you can see a switch statment with the 10 levels I created. They all call different functions and variables to setup the level. Each one is described below:
Test runtime (veloce)
---------------------
**playerPosition;** Where the player starts on the 0 to 1000 line. If not set it defaults to 0. I set it to 200 in the first level so the player can see movement even if the first action they take is to push the joystick left
1. Collega l'ESP32 al PC via USB.
2. Apri il monitor seriale:
**spawnEnemy(position, direction, speed, wobble);**
* position: 0 to 1000
* direction: 0/1, initial direction of travel
* speed: >=0, speed of the enemy, remember the game is 1000 wide and runs at 60fps. I recommend between 1 and 4
* wobble: 0=regular moving enemy, 1=sine wave enemy, in this case speed sets the width of the wave
```powershell
platformio device monitor --baud 115200
```
**spawnPool[poolNumber].Spawn(position, rate, speed, direction);**
* A spawn pool is a point which spawns enemies forever
* position: 0 to 1000
* rate: milliseconds between spawns, 1000 = 1 second
* speed: speed of the enemis it spawns
* direction: 0=towards start, 1=away from start
1. Invia il comando `debug` seguito da invio: questo attiva la modalità debug nel gioco e dovrebbe mostrare un pixel bianco che si muove lungo la striscia.
**spawnLava(startPoint, endPoint, ontime, offtime, offset);**
* startPoint: 0 to 1000
* endPoint: 0 to 1000, combined with startPoint this sets the location and size of the lava
* ontime: How lomg (ms) the lava is ON for
* offset: How long (ms) after the level starts before the lava turns on, use this to create patterns with multiple lavas
Comandi seriali disponibili
--------------------------
**spawnConveyor(startPoint, endPoint, direction);**
* startPoint, endPoint: Same as lava
* direction: the direction of travel 0/1
- `debug` — entra in modalità debug (pattern di prova)
- `restart` — riavvia la board
- `a`, `d`, `w`, `s` — movimenti/azioni (utili per test da seriale)
- `status` — stampa stato (placeholder)
**spawnBoss()**
* There are no parramaters for a boss, they always spawn in the same place and have 3 lives. Tweak the values of Boss.h to modify
Controlli fisici
----------------
Feel free to edit, comment on the YouTube video (link at top) if you have any questions.
- `BUTTON_LEFT` -> GPIO 15
- `BUTTON_RIGHT` -> GPIO 2
- `BUTTON_ATTACK`-> GPIO 4
- `BUTTON_START` -> GPIO 5
Nota hardware sui LED
---------------------
- Usa resistenza 330-470 Ω sul line DATA tra ESP32 e prima LED consigliata.
- Usa condensatore 1000 µF vicino alla strip tra +V e GND per stabilizzare alimentazione.
- Assicurati che l'alimentazione della strip supporti il numero di LED (circa 60mA per LED a piena intensità RGB).
Cose da verificare se qualcosa va storto
--------------------------------------
- Errori in compilazione: controlla l'output di `platformio run` e cerca file/righe menzionate.
- Problemi con LED che non accendono: verifica pin `DATA_PIN` in `src/config.h` e il cablaggio fisico.
- Striscia parzialmente corretta o colori sbagliati: prova a cambiare `NeoGrbFeature` in `LedController.h` (alcuni LED usano GRB o RGB) — apertura possibile modifica: `NeoRgbFeature`/`NeoGrbFeature`.
- Problemi di crash o reset: verifica consumo memoria (PlatformIO log mostra RAM/Flash) e alimentazione.
Note tecniche rilevanti
----------------------
- `LedController` usa `new NeoPixelBus<>` dinamico per evitare static init order problems; non ci sono delete espliciti perché la durata è quella della app.
- `fadeAll` è implementato manualmente leggendo `GetPixelColor` e scalando componenti.
- `Player::reset()` non accetta parametri: ogni chiamata nel progetto è stata adattata per usare la versione senza argomenti (correzioni in `Level.h`).
Miglioramenti possibili
----------------------
- Aggiungere un semplice pattern di test automatico all'avvio per diagnosticare la strip senza interazione seriale.
- Implementare un piccolo unit-test harness (non comune per Arduino, ma possibile con framework) per la logica core.
Se vuoi che proceda con l'upload automatico o ad aggiungere il pattern di test all'avvio, dimmelo e lo aggiungo subito.