Skip to content

Instantly share code, notes, and snippets.

@johnwargo
Last active October 29, 2023 15:45
Show Gist options
  • Save johnwargo/e6b19e2d2b905ac7a61d061ea952e482 to your computer and use it in GitHub Desktop.
Save johnwargo/e6b19e2d2b905ac7a61d061ea952e482 to your computer and use it in GitHub Desktop.
An Arduino random smoke generator
#define SMOKE_PIN A0
#define MIN_SMOKE_TIME 1000
#define MAX_SMOKE_TIME 5000
void setup() {
// configure the output pin to control the smoke generator
pinMode(SMOKE_PIN, OUTPUT);
// Enable the Arduino device's onboard LED
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// turn the smoke machine on
digitalWrite(SMOKE_PIN, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
// leave it on for a random time between MIN_SMOKE_TIME
// and MAX_SMOKE_TIME (in milliseconds)
delay((int)random(MIN_SMOKE_TIME, MAX_SMOKE_TIME));
// turn the smoke machine off
digitalWrite(SMOKE_PIN, LOW);
digitalWrite(LED_BUILTIN, LOW);
// Wait for another random amount of time
delay((int)random(MIN_SMOKE_TIME, MAX_SMOKE_TIME));
// Go back and do it again
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment