Hi guys I tried optimizing the code,
And would like to get rid of delays.
I use the encoder.h and put the encoder value into a If statement and switch off and on a led for a period of time. If have done it with delays but it’s kinda buggy.
Could someone explain how to wrap the two integers? Because the digital pin for on/off shows miniature random spikes of a few microseconds.
I tried to wrap the if statement in the beginnin with
I tried wrapping the int itself,
I tried reformulating the if statements based on time stamp and when the millis() is overloading.
should I make a different newMillis for the OnTime?
And would like to get rid of delays.
I use the encoder.h and put the encoder value into a If statement and switch off and on a led for a period of time. If have done it with delays but it’s kinda buggy.
Code:
Int OnTime=1000; Offtime=1000;// independent values
Unsigned long PreviousMillis=0;
Void setup()
{}
Void loop()
{
unsigned long newMillis= millis();
If(Ledstate==HIGH)
{
If((newMillis-PreviousMillis)>=OnTime)
{
Ledstate==LOW;
}
PreviousMillis=newMillis();
}
Else
{
If((newMillis-PreviousMillis)>=Offtime)
{
Ledstate==HIGH;
}
PreviousMillis=newMillis();
}
}
Could someone explain how to wrap the two integers? Because the digital pin for on/off shows miniature random spikes of a few microseconds.
I tried to wrap the if statement in the beginnin with
Code:
if((unsigned long) do something...) ,
I tried reformulating the if statements based on time stamp and when the millis() is overloading.
should I make a different newMillis for the OnTime?