Skip to content

Add lightsaber demo for y-board v4 - #13

Draft
philipbl wants to merge 12 commits into
mainfrom
claude/accelerometer-lightsaber-sound-8JoxL
Draft

philipbl wants to merge 12 commits into
mainfrom
claude/accelerometer-lightsaber-sound-8JoxL

Conversation

@philipbl

@philipbl philipbl commented Mar 27, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds a lightsaber demo that uses the accelerometer to detect motion and play lightsaber sounds
  • Idle hum when stationary, swing sounds on movement, clash sounds on hard swings
  • LEDs glow in saber color with subtle flicker effect; knob controls brightness
  • Switches select saber color: green, blue, red, or purple
  • Knob button toggles saber on/off with extend/retract LED animation
  • Expects sound files on SD card under /lightsaber/ (wav or mp3)

TODO

  • Add lightsaber sound files to the SD card under /lightsaber/:
    • hum.wav or hum.mp3 — idle lightsaber hum loop
    • swing.wav or swing.mp3 — swing whoosh sound
    • clash.wav or clash.mp3 — hard hit/clash sound
    • on.wav or on.mp3 — power-on ignition sound
    • off.wav or off.mp3 — power-off retraction sound

Test plan

  • Upload sound files to SD card under /lightsaber/
  • Flash demo to y-board v4
  • Verify knob button toggles saber on/off with LED animation
  • Verify idle hum plays continuously when stationary
  • Verify swinging the board triggers swing/clash sounds
  • Verify switches change saber color (green/blue/red/purple)
  • Verify knob adjusts LED brightness

Closes #4

https://claude.ai/code/session_011mUJCo2axqDYJwe7GyJ1zR

claude added 8 commits March 27, 2026 02:11
Uses accelerometer to detect motion and plays lightsaber sounds.
Features idle hum when stationary, swing sounds on movement, and
clash sounds on hard swings. LEDs glow in saber color with flicker
effect. Switches change saber color (green/blue/red), knob button
toggles on/off with extend/retract animation.

Tries sound files from /lightsaber/ on SD card (hum, swing, clash,
on, off) with play_notes fallback when files aren't present.

Closes #4

https://claude.ai/code/session_011mUJCo2axqDYJwe7GyJ1zR
Both switches on (SW1 + SW2) now selects purple. The four
switch combos give green, blue, red, and purple.

https://claude.ai/code/session_011mUJCo2axqDYJwe7GyJ1zR
- abs() on floats is undefined on ESP32, causing a null pointer
  dereference. Use fabsf() from <cmath> instead.
- When sound files are missing, the hum loop was retrying every 30ms
  which could crash the audio subsystem. Now only retries after the
  hum interval elapses.
- Add Serial debug prints for file paths being opened.

https://claude.ai/code/session_011mUJCo2axqDYJwe7GyJ1zR
Allows LED extend/retract animation to run simultaneously with
the sound instead of waiting for the sound to finish first.

https://claude.ai/code/session_011mUJCo2axqDYJwe7GyJ1zR
@philipbl
philipbl marked this pull request as draft March 28, 2026 17:29
claude and others added 4 commits March 29, 2026 04:44
Instead of replaying on a fixed timer, check is_audio_playing()
and only restart the hum when it has finished. This avoids
hammering the SD card with repeated file opens.

https://claude.ai/code/session_011mUJCo2axqDYJwe7GyJ1zR
Calling play_sound_file while audio is already playing (e.g. hum
playing when a swing triggers) causes a crash. Now try_play_file
always calls stop_audio() first. Removed redundant stop_audio()
calls elsewhere since try_play_file handles it.

https://claude.ai/code/session_011mUJCo2axqDYJwe7GyJ1zR
Only start a new swing or clash sound when swing_end_time is 0,
meaning the previous swing has finished. This prevents hammering
the SD card with repeated file opens during continuous motion.

https://claude.ai/code/session_011mUJCo2axqDYJwe7GyJ1zR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add lightsaber demo

2 participants