Skip to content

Instantly share code, notes, and snippets.

@makersylvia
Last active October 3, 2021 05:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makersylvia/9b133cb2d38c4052bd55 to your computer and use it in GitHub Desktop.
Save makersylvia/9b133cb2d38c4052bd55 to your computer and use it in GitHub Desktop.
Code for the Super-Simple strobe Arduino project
// Gray text are just helpful comments, you don’t need to type them. :)
/******* -----=====!! EASY STUFF TO MESS WITH !!=====------ ******/
// What analog pin should we use to read the value from the potentiometer?
int analogPin = 2; // Yep, you heard right: The coolest of the Analog pins...
// What pin is the LED connected to?
int ledPin = 13; // Contains a built in resistor!
// How much time should the light stay on between delays, in Microseconds (millionths of a second)?
/* Big number = more blur, more perceived brightness
* Small number = less blur, less perceived brightness */
long onTime = 250;
// What should the minimum delay be in milliseconds (thousandths of a second)?
// This sets the bottom delay range of the strobe, as a delay of 0 doesn't actually flash =P
// The strobe starts with this as the "fastest" mode, and goes slower from there, adding to the delay
int minDelay = 1; // 1 is the lowest we can actually do without a better delay function
// What should the maximum delay be in milliseconds?
// This is the longest time that the biggest potentiometer value will be mapped to, and longest
// time between strobe flashes.
int maxDelay = 100;
/******* -----=====^^ EASY STUFF TO MESS WITH ^^=====------ ******/
// Initialize the number to hold our strobe delay. Isn't used till we get to the main loop
long strobeDelay = 0;
void setup() {
pinMode(ledPin, OUTPUT); // Setup ledPin as an output.
}
void loop() {
// To make the math easier, we use map(value, fromMin, fromMax, toMin, toMax) to convert the
// 0 to 1023 range we get from analogRead, into our strobe delay range of 1 to 100 :D
strobeDelay = map(analogRead(analogPin), 0, 1023, minDelay, maxDelay);
digitalWrite(ledPin, HIGH); // Switch the ledPin to HIGH, turn it on!
delayMicroseconds(onTime); // Delay while on, for the given onTime.
digitalWrite(ledPin, LOW); // Switch the ledPin to LOW, turn if off!
delay(strobeDelay); // Delay while off, for given strobeDelay.
}
@glibg10b
Copy link

glibg10b commented Oct 3, 2021

One design issue is that the loop waits for the delay to finish before continuing, so if the pot is near 0, the LED won't instantly respond when the pot gets adjusted. This causes the strobe to feel unresponsive at low frequencies. I'll see if I can do something about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment