There are currently 0 users and 6 guests online.
C++ Library for $50 robot Version 2
Submitted by Webbot on January 2, 2009 - 12:08am.
This class is used to generate a PWM signal on ANY outout pin using software rather than hardware timers. The granularity of the timer is multiples of 1ms. Hence it is not suitable for servos but is ideal for driving DC motors, dimming LEDs etc.
This class extends Out.hpp so that it can use any output pin.
To create an output which is high for every 1ms per 20ms on port D5 use:
PWMOUT pin('D',5, 20, 1);
The duty cycle can be varied, ie by modifying the last parameter given in the constructor, by:-
void setOnTime(uint16_t onTime); // set the number of ms when the signal is high
uint16_t getOnTime(); // get the number of ms when the signal is high - either from constructor or last call to setOnTime
uint16_t getCycleTime(); // get the ms per cycle as given in the constructor
So if you want an LED on port D5 to flash for 1 second every 3 seconds then just declare:
PWMOUT led('D',5,3000,1000); // Thats all you need to do!!!!!