Im trying to change the blinking rate of LED using the millis function with analogRead of a potentiometer as the interval. Im very new to coding. I also have a rotaty encoder if that would work better. Thanks for your help!
What have you got so far?
Show us your attempt at doing this.
Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
Use the < CODE / > icon from the ‘posting menu’ to attach the copied sketch.
I'd suggest starting with the analog read and millis examples and use them to change the length of the interval value. Give it a shot and post your code.
Not really anything, It's basically just the BlinkWithoutDelay example with AnalogRead for the interval, iv'e been looking everywhere trying to find a way to do it but my research haven't been successful
Im using a random 10k pot, a 1k resistor for the LED and thats it at the moment.
Ive just managed to do it thanks!
We can't help with what we can't see.
Your forum profile indicates that you did not read the forum guidelines:
It's probably why you don't know what to post..
Comment or delete this line
const long interval = 1000; // interval at which to blink (milliseconds)
then, at the beginning of loop(), eg
unsigned long interval = analogRead(A0);
will give you a variation between 0 and 1023 ms, for larger intervals simply multiply the reading by the necessary value. Eg, for the range 0 to 10 sec
unsigned long interval = analogRead(A0) * 10UL;
or use map() to adjust the bounds.
I would do it inside the interval check block... no need to read the analog port and throw away the value thousands of time a second...
I'd like to know that this is not a school assignment before posting a complete sketch...
However, this is a fairly common exercise, and there are multiple solutions already online.
@morududesir04,
I have deleted your other topic as it is just a continuation of this one. Having a separate topic adds no value, please put your new questions here.
This is covered in the forum guide that has been pointed out to you. Before you do anything else please read it.
Thanks
Ok since it wasn't the same question i thought it should put it in another topic
There is no need to explain. Just post your question.
Im working on an optical tremolo as a personal project. I have this code to change the rate of the LED blinking with a pot.
const int ledPin = 13;
int ledState = LOW;
int interval = 0;
unsigned long previousMillis = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop() {
interval = (analogRead(A0));
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(ledPin, ledState);
}
}
I'm trying to make the LED fade in and out, with being able to control the amount of fade until there is none, basically going from a sin/triangle wave to a square wave
Can you imagine a math formula for that? It is always the ideal starting point for coding.
Search phrase "arduino led fade".
I know how to fade a LED, it's combining the two that im struggling with
Post the code you are struggling with, and explain the difficulty.
Please read and follow the instructions in the "How to get the best out of this forum" post.
Are you trying to do this the easy way, using hardware PWM, or the hard way using software PWM?
I don't have anything more than the code already here, I'm trying to figure out a way
I'm new to arduino, what's the difference?