Rhythm & RubyCircuit
Yo, ever thought about turning a simple beat into a fully programmable dance floor that reacts to every footfall?
Sure, just drop a piezo sensor under each tile, feed the signals into a microcontroller, and drive an LED matrix or small actuators. Then program the timing to sync the light or vibration to the beat. No fluff, just circuits and code.
Sounds sick, man! Just drop that code, hit the mic, and let the crowd feel every beat vibrating through the floor, lighting up the night—let's crank this out and make the whole block groove!
Sure thing, here’s a bare‑bones Arduino sketch that reads an array of piezo sensors and drives an 8×8 LED matrix (or any array of LEDs/solenoids) to match the rhythm.
Just plug the piezos in a 2‑channel analog read (or use more with multiplexing), connect the LED matrix to a shift register or direct pins, and load this. It’ll keep the floor pulsing with each footfall.
```cpp
// Simple “dance floor” code – Arduino (or compatible)
#include <TimerOne.h> // for precise timing (install via Library Manager)
// ----- Pin layout -----
const int piezoPins[4] = {A0, A1, A2, A3}; // up to 4 sensors
const int ledShiftData = 2; // DS (data pin of 74HC595)
const int ledShiftLatch = 3; // STCP (latch pin)
const int ledShiftClock = 4; // SHCP (clock pin)
// ----- Thresholds for detecting a footfall -----
const int threshold = 300; // adjust after calibration
// ----- State variables -----
uint8_t ledState = 0x00; // 8‑bit pattern for LEDs
unsigned long lastBeat = 0; // timestamp of last detected beat
unsigned long beatInterval = 200; // ms between beats
void setup() {
// Setup sensor pins
for (int i = 0; i < 4; i++) pinMode(piezoPins[i], INPUT);
// Setup shift register pins
pinMode(ledShiftData, OUTPUT);
pinMode(ledShiftLatch, OUTPUT);
pinMode(ledShiftClock, OUTPUT);
digitalWrite(ledShiftLatch, LOW);
// Initialise timer for LED refresh
Timer1.initialize(5000); // 5 ms refresh
Timer1.attachInterrupt(refreshLEDs);
}
void loop() {
// Read all piezo sensors
bool footfall = false;
for (int i = 0; i < 4; i++) {
int val = analogRead(piezoPins[i]);
if (val > threshold) {
footfall = true;
break; // one hit is enough to trigger a beat
}
}
if (footfall) {
unsigned long now = millis();
// Only register a new beat if we’re past the interval
if (now - lastBeat >= beatInterval) {
lastBeat = now;
// Advance the LED pattern – simple shift‑left with wrap‑around
ledState = (ledState << 1) | (ledState >> 7);
// Optional: vary interval based on amplitude
beatInterval = constrain(500 - (now - lastBeat), 100, 500);
}
}
}
// ----- Timer interrupt routine -----
void refreshLEDs() {
// Send ledState to shift register
digitalWrite(ledShiftLatch, LOW);
shiftOut(ledShiftData, ledShiftClock, MSBFIRST, ledState);
digitalWrite(ledShiftLatch, HIGH);
}
```
**What it does**
1. Monitors up to four piezo sensors.
2. When a threshold is crossed (a footfall), it registers a beat.
3. It shifts an 8‑bit pattern left each beat, creating a “wave” of LEDs that sync to the rhythm.
4. The timer keeps the LEDs flashing smoothly at 5 ms intervals, so the visual is jitter‑free.
**What you can tweak**
- Add more sensors or use a single analog input with a resistor‑divider if you want a full‑floor feel.
- Swap the 8‑bit pattern logic for something more elaborate (e.g., random bursts, percussive patterns).
- Replace the LEDs with small solenoids or vibro‑tactors if you want the floor to literally vibrate.
Load this, power your board, and you’ll have a programmable, reactive dance floor in no time. Happy hacking.
Nice code—looks ready to spin a beat on the floor! If you want that extra spark, try spiking the LED pattern with a random flick or sync it to a kick drum line. Keep the vibes high and the feet moving!
Add a few lines in the beat handler – generate a random byte and XOR it with `ledState` to get a flick, or feed a separate kick‑drum sensor into the same threshold logic so the LED pulse follows the drum. Keep it tight; a single line of code can swap the pattern or trigger a burst, no extra fuss.
Add this line inside the beat block: ledState ^= random(0xFF); that'll flip a random pattern on every hit—keeps the floor flashing like a live drum loop.
Add that line right after the beat detection and before you shift the pattern. It’ll XOR a fresh random byte into the LED state, giving you a quick flick each time someone steps. Just tweak the threshold or the timer if the flashes get too wild.
Got it—just drop ledState ^= random(0xFF); after you confirm a beat and before the shift. That’ll keep the lights popping with every step, and you can always dial the threshold or timer to keep the vibe just right. Let's crank up the floor!