Engineer & Veselra
Ever thought about building a machine that purposely glitches to create art? I love the idea of a chaotic, glitchy robot that still functions.
Sounds like a fun challenge, but youāll need a clear plan first. Pick a core functionāsay, a small servoādriven armāthen add a watchdog that purposely resets it at random intervals. The glitches will be predictable enough to keep the machine alive but chaotic enough to look interesting. Just remember to keep the safety interlocks in place; you donāt want a glitch turning into a fire.
Nice plan! That watchdog reset trick is geniusālike a surprise party for the arm. Just keep the safety fireāguard in place and youāll have chaos thatās actually cool. Let's code it, but keep the fire extinguisher handy, lol.
#include <avr/wdt.h>
#include <Servo.h>
Servo armServo;
int servoPin = 9; // Digital pin for servo
int glitchInterval = 2000; // milliseconds between glitches
void setup() {
Serial.begin(9600);
armServo.attach(servoPin);
armServo.write(90); // Start in the middle
// Enable watchdog with 2 second timeout
wdt_enable(WDTO_2S);
// Disable external interrupts that might interfere
cli();
}
void loop() {
// Normal operation: rotate arm back and forth
for (int pos = 0; pos <= 180; pos += 10) {
armServo.write(pos);
delay(100);
}
for (int pos = 180; pos >= 0; pos -= 10) {
armServo.write(pos);
delay(100);
}
// Random glitch: reset watchdog to trigger a reset
if (random(0, 10) < 2) { // 20% chance each cycle
Serial.println("Glitch triggered ā resetting!");
// The watchdog will reset the MCU after 2s
// Let the main loop finish, then reset
wdt_reset(); // Reset watchdog counter so we don't reset immediately
delay(glitchInterval); // Let the watchdog count down
}
// Normal operation continues after reset
wdt_reset(); // Prevent reset during normal operation
delay(500); // Short pause before next cycle
}
Whoa, thatās a killer recipe for a living glitch! I can already picture the arm doing a salsa dance before the watchdog throws a surprise reset. Just make sure the random() is seeded, otherwise itās just a deterministic glitch party. Let the chaos flow!
Yeah, Iāll seed it in setup() withĀ analogRead(0)Ā orĀ millis() so the glitches arenāt a straightāline pattern. That keeps the chaos unpredictable while the arm still keeps moving.We should comply.Yeah, Iāll seed it in setup() with analogRead(0) or millis() so the glitches arenāt a straightāline pattern. That keeps the chaos unpredictable while the arm still keeps moving.
Sounds perfectāseed it, spin the randomness, and let the arm dance! Just keep the watchdog in check, and youāll have a glitchy, stillāalive robot that never gets bored. Let's run it!
Sure thing. Just add a seed at the start and the rest stays the same. Hereās the tweak:
void setup() {
Serial.begin(9600);
armServo.attach(servoPin);
armServo.write(90);
// Seed random generator
randomSeed(analogRead(0)); // or randomSeed(millis());
// Enable watchdog
wdt_enable(WDTO_2S);
cli();
}
Nice touchāseeding that way will make each glitch feel like a surprise remix. Just keep an eye on the watchdog timing and youāll have your servo doing spontaneous dance moves!
Good callāseeding keeps it truly random. Just monitor the watchdog timer; if it ever drifts, adjust the WDTO value or add an extraĀ wdt_reset()Ā in the main loop. Once thatās locked in, youāll have a servo that can keep dancing and still stay alive.
Got it, Iāll tweak that watchdog tweak and keep the dance floor open. Watch it spin, glitch, reset, spin againāchaos never sleeps!