help with Timer with TURN ON / OFF PWM

Hi Folk,

I am newbie in programming, and start to learn step by step and understanding how each of the code work and implemented to.

I am building a timer from code that I found on web, and I am able to used it for now, BUT my biggest archived is able to make the PWM on the time ON and OFF
At a moment these timer is connected to a relay (witch will turn relay ON on the ON TIME Period and reverse).
I am trying to moved from relay to some kind of power transistor / FET. for example :
10 second or so before it switch ON and OFF it start the PWM sequences.
SO on the ON period it will start the output (within interval 10 second) increase the voltage from 0 to FULL power
and
for the OFF period (within 10 second before countdown reach 0 second) start to turning OFF slowly from full power to 0

I was thinking to use the FADE example (and actually these what I am looking for) BUT I am confuse to implemented to the current code

the current code is :

void refreshTime()
{

if (timeLeft == 0) {
outState = !outState;

timeLeft = (outState?timeOn:timeOff) - 1;

lcd.clear();
lcd.print(" “);
lcd.print(timeLeft);
lcd.print(” sec");
lcd.setCursor(0,1);
lcd.print("Next “);
lcd.print(!outState?” ON “:” OFF ");
lcd.print(!outState?timeOn:timeOff);
lcd.print(“s”);

digitalWrite(outputPin, outState?HIGH:LOW);

} else {
timeLeft–;

lcd.setCursor(5,0);
lcd.print(" “);
lcd.setCursor(5,0);
lcd.print(timeLeft);
lcd.print(” sec");
}

at that code it’s clearly shown to write HIGH or LOW to the output pin relevant to the time ON / OFF interval.

any help will be appreciate

thanks

at that code it's clearly shown to write HIGH or LOW to the output pin relevant to the time ON / OFF interval.

How frequently does that code change the state of a pin? How frequently does the analogWrite() function change the state of a pin? The frequencies are not even comparable.

10 second or so before it switch ON and OFF it start the PWM sequences.

How is "it" (whatever it is) supposed to know that something is going to happen in the future?

Hi PaulS,

the output pin goes HIGH or LOW is depending on the SET time (in second) and its going on and on until the power supply is disconnected. that code is white on the setup () ;

at the beginning declare the outState to false

boolean outState = false;

and the loop() as bellow :

void loop()
{

catchRotary();
catchButton();
t.update();
}

I am attach the complete code on these timer.

code.txt (7.09 KB)