Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:32 25 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Arduino to MMbasic

Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 10:02pm 24 Jun 2024
Copy link to clipboard 
Print this post

I have a line in a small Arduino sketch that turns on a led for a random length of time
analogWrite(ledPin1, random(50)+125)

This I take it switches ledPin1 on for a random length of time plus 125, but 125 what are they milliseconds.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1109
Posted: 10:12pm 24 Jun 2024
Copy link to clipboard 
Print this post

That randomly sets the brightness of the LED. Analogwrite() generates an 8 bit PWM on the specified pin. So the random brightness is between roughly 1/2 and 3/4 bright.
Visit Vegipete's *Mite Library for cool programs.
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 896
Posted: 10:16pm 24 Jun 2024
Copy link to clipboard 
Print this post

I think it may be the duty cycle for a PWM signal.
I have no experience know but this is google result.

The function used to output a PWM signal is analogWrite(pin, value). pin is the pin number used for the PWM output. value is a number proportional to the duty cycle of the signal.

Footnote added 2024-06-25 08:17 by disco4now
Too slow !
Latest F4 Latest H7
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024