I want to modify the code by using timers to avoid problems when using push buttons to change the pulsewidth.I tried the millis() function,but can't figure out why is it not working like that;the output is always high.Here is the code for that:
That's not safe. See the Blink Without Delay example for an example of how to do this right. It should involve subtraction and the greater than operator.
Remember, every now and then millis skips a number. If you want to time off 1 millisecond then maybe you should use micros instead of millis.
Don't mind Paul. He's a bit, how shall we say, "Special". Your code is short enough that everyone else can see what your state variable does. Paul has an issue, if he can't see the problem then he feels inadequate so he lashes out and uses abusive language with the person who asked the question he isn't smart enough to answer. He can't just leave it for one of us who actually has some reading skills to come along and help.
Don't worry, he's just an old nobody. I guess his mom didn't teach him how to be considerate of anything. Not all of us have good mothers who teach us good things. Some folks have crack whores for moms. That doesn't make them bad people, but it sometimes makes them hard to be around. And maybe that's what we have with good ole PaulS. Or maybe it's something else. Who knows. It's usually best if you just ignore him and pretty soon he'll be back outside yelling at the clouds or something.
He is at his best when he is making up his own definitions for words, like "button", and then berates anyone who uses the commonly accepted (Websters / Oxford) definition instead of his special made up definition and calls them stupid for using words the way they are used in real English instead of his special autist speak language.
Hi again,
I managed to get the code working,by using the micros() function and also by changing the == to >= in these type of situations: if(millis() == prevmillis + 1)
I just think that those kind of people like the first answerer should not be allowed to comment offensive messages,no matter if they are just too lazy to answer,or know nothing.
SmileXS4:
Hi again,
I managed to get the code working,by using the micros() function and also by changing the == to >= in these type of situations: if(millis() == prevmillis + 1)
That's still wrong. If you let the code run for a long time you will eventually find that one interval waits for 49 days. This must always be done with subtraction to take advantage of the variable rollover.
Do it the right way, the way that it is done in all the Blink Without Delay examples. There's plenty of tutorials around on how that works.
SmileXS4:
I just think that those kind of people like the first answerer should not be allowed to comment offensive messages,no matter if they are just too lazy to answer,or know nothing.
I think @PaulS should really be ashamed of himself for his continued use of vulgarity and profanity around children. The man has no shame. But what are you gonna do? This is the internet and there are all kinds of horrible people on the internet. You can't get rid of them. So you just have to ignore them.
What a pitiful little excuse for a man though. Don't you agree? I feel for him. I wish I could help him see that there is more to life than building yourself up in your own mind be being mean to others. You know how rotten his soul must be. It must really be horrible to live in that skin.