Timeline for how to apply a timer to an analogWrite command for Arduino
Current License: CC BY-SA 4.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 3, 2019 at 22:47 | comment | added | MAB | functionally, digitalWrite(LOW) is equivalent to analogWrite(0), digitalWrite(HIGH) is equivalent to analogWrite(255) if the pin is PWM capable. I can only encourage you to use arduino.cc/reference/en more, it has a lot of useful information. | |
| Jul 3, 2019 at 21:08 | comment | added | kwhunter | sorry MAB, I cannot vote since I do not have enough privileges. The code is Ok, I didn't know you can turn on an output with an analogWrite and turn it off with a digitalWrite... Someone wrote another code for me, but it is a more advanced use of commands and therefore not as easy to add the PWM function, in my opinion. I will google for the millis overflow; if I cannot handle, I will just turn the board off every week... | |
| Jul 3, 2019 at 20:40 | comment | added | MAB | no, millis() returns the number of milliseconds since you powered-up the board, it keeps counting until it reaches its max value, then goes back to zero (after ~50 days according to arduino documentation: arduino.cc/reference/en/language/functions/time/millis). you can guard against it with an if statement, or some clever math, there are examples you can easily find, this is NOT an unusual thing. also, if that's been helpful to you, consider up-voting and select the answer. If you think I should change something specific in the code I gave in my answer, I can do that too. | |
| Jul 3, 2019 at 17:50 | comment | added | kwhunter | I made some edits to your program since the fan was ON all the time and when timer 2 kicked in it changed speed since A0 controlled it; now it works as it should, thanks. Aren't the millis() reset each cycle? if not what can I do to prevent the overflow? | |
| Jul 3, 2019 at 17:14 | comment | added | MAB | Thinking back at my note#4, the resulting program would actually be different, since while the fan is on, it would immediately react to a change on A0, which is arguably better. your initial program with the on-off structure would have been easily implemented with delay() - also if you plan to run this program for a very long time, you will have an unexpected behavior when millis() overflows. | |
| Jul 3, 2019 at 16:51 | comment | added | kwhunter | No I did not, application not critical; for the record, I use the fan to move around the air in the Humidor for the temperature and humidity to even out. Current setting is 1 minute ON and 15 minutes off. | |
| Jul 3, 2019 at 0:17 | comment | added | MAB | @kwhunter have you tried to use the Serial monitor to make sure your initial program does what you think it does? It's extremely useful to debug arduino code. A few thing to monitor: does the fan turn on/off when you think your code turns it on/off. You also should monitor the PWM_Value before and after map, to make sure you are feeding analogWrite with the proper parameter. These would be the first things I look at. | |
| Jul 2, 2019 at 21:06 | comment | added | kwhunter | you've got it right; I use a BUZ11 N-channel MOSFET to control the fan. The code as it is now, works fine: the LED is on only when the fan is on. I tried replacing the digital Write with the analogWrite as suggested but it didn't work so that's why I posted the code here. It's obvious I'm not an experienced programmer... | |
| Jul 2, 2019 at 21:00 | review | First posts | |||
| Jul 2, 2019 at 21:20 | |||||
| Jul 2, 2019 at 20:57 | history | answered | MAB | CC BY-SA 4.0 |