I want to use pwm of positive pulses of 1000 to 2000 microseconds and about 20 milliseconds apart to just turn on and off arduino nano built in led. How do i do this?
You could:
use millis()
Setup a timer
use delay for on time and millis() for period.
What else will you need to run on this board? What board are you using?
Those signals are typical RC (radio control) servo commands, and you can use the RCReceiver or RC_ESC libraries to interpret them any way you like.
sounds like a school assignment
- make sure the pin is configured as OUTPUT
- use digitalWrite to set the state of the pin to LOW or HIGH. LEDs are typically active LOW
- use delay() after setting the output state for the desire period of time
const byte InputPin = 4;
void setup()
{
pinMode(InputPin, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
unsigned long pulseLength = pulseIn(InputPin, HIGH, 30000);
if (pulseLength != 0) // Ignore timeouts
digitalWrite(LED_BUILTIN, pulseLength > 1500);
}
1 Like
Or see this thread and posted code
which takes the on/off idea a step further. This can be used so the action doesn’t happen until the control pulses come in at the large end, and doesn’t stop until they come in at the small end of the range for the pulse width.
An example of hysteresis.
HTH
a7
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.