Reputation: 33
My plan is to make an adjustable speed strobe. I'm just learning to code and this is what I have so far.
int potentiometer_pin = A0;
int led_pin = 7;
int on_time = 100;
int analog_value_multiplier = 15;
int strobe_delay = 0;
int minimum_delay = 500;
void setup() {
pinMode(led_pin, OUTPUT);
}
void loop() {
strobe_delay = minimum_delay + analogRead(potentiometer_pin) * analog_value_multiplier;
digitalWrite(led_pin, HIGH);
delayMicroseconds(on_time);
digitalWrite(led_pin, LOW);
delayMicroseconds(strobe_delay - on_time);
}
I have the LED + on digital 7 with a 220ohm resistor and the pot on analog 0, it is a 10K pot with one side hooked up to 5v+ and the other to ground. My problem is that the LED stays on and turning the pot just changes the brightness. Any help on what to do - not just a new code but what to do? I want to actually learn how to fix this.
Upvotes: 2
Views: 713
Reputation: 6983
like david said, but I will add I think you want delay not delayMicroseconds.
http://arduino.cc/en/Reference/delay
Upvotes: 4
Reputation: 182829
Your speeds are all WAY too fast. Multiply all your delays by about 100. You've made a pulse width modulator.
Upvotes: 3