10 years, 4 months ago.

How to enable/disable PwmOut?

I want to set up a pwm signal and then enable and tri-state disable it (set to input?).

I tried:

DigitalInOut d( p21); PwmOut p( p21 );

p.period_us(100.0); p.write(0.5); wait(2.0); d.input(); wait(2.0); d.output();

but that doesn't work.

2 Answers

10 years, 4 months ago.

If you are in a hurry you will need to directly change the pin config register yourself. If it isn't that much of a hurry, you can either use new and delete, and dynamically make them, or something similar:

while(1) {
  DigitalInOut d(p21);
  d.input();
  wait(2);
  PwmOut p(p21);
  p.period_us(100);
  p.write(0.5);
  wait(2);
}

6 years, 7 months ago.

PWM.write(0) might be what you are looking for