This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
digispark:tutorials:propwm [2015/01/12 15:10] digistump created |
digispark:tutorials:propwm [2016/06/09 12:03] (current) |
||
|---|---|---|---|
| Line 11: | Line 11: | ||
| The standard Arduino analogWrite function works with the Pro. Using analogWrite(pin,value) where pin is the pin number, and value is the PWM value you want to set that pin to - works just like a regular Arduino and sets that pin to that value and disconnects all other pins on that channel from the PWM channel. This means with analogWrite you can have one pin on each channel active at a time. | The standard Arduino analogWrite function works with the Pro. Using analogWrite(pin,value) where pin is the pin number, and value is the PWM value you want to set that pin to - works just like a regular Arduino and sets that pin to that value and disconnects all other pins on that channel from the PWM channel. This means with analogWrite you can have one pin on each channel active at a time. | ||
| + | |||
| + | Note: Pin 8 PWM functionality is accessed only with analogWrite - since it is the only pin on that channel the other functions below are not needed | ||
| =====Special PWM functions:===== | =====Special PWM functions:===== | ||
| - | The Digispark Pro also has the following special functions available for use with the PWM functionality: | + | The Digispark Pro also has the following special functions available for use with the PWM functionality on Pins 0-4 **(these are not used for Pin 8 - see note above)**: |
| **pwmWrite(channel,value);** | **pwmWrite(channel,value);** | ||
| Line 34: | Line 36: | ||
| Disconnect all pins from their PWM channel. | Disconnect all pins from their PWM channel. | ||
| + | **Example:** | ||
| + | <code> | ||
| + | void setup() { | ||
| + | pwmConnect(0);//connect pin 0 to its channel (A) | ||
| + | pwmConnect(1);//connect pin 1 to its channel (B) | ||
| + | pwmWrite(CHANNELA,127); //set channel A to 1/2 PWM output - therefore pin 0 is at 50% PWM output | ||
| + | pwmWrite(CHANNELB,63); //set channel B to 1/4 PWM output - therefore pin 1 is at 25% output | ||
| + | delay(1000); | ||
| + | pwmConnect(4);//connect pin 4 to its channel (B) - pin 4 is now also at 25% output | ||
| + | delay(1000); | ||
| + | pwmWrite(CHANNELB,255); //set channel B to 100% PWM output - therefore pin 1 and 4 are at 100% output | ||
| + | delay(1000); | ||
| + | pwmDisconnect(1);//disconnect pin 1 from its channel (B) - pin 1 is no longer outputting the PWM signal | ||
| + | pwmConnect(2);//connect pin 2 to its channel (A) pin 2 is now also at 50% PWM output | ||
| + | pwmConnect(3);//connect pin 3 to its channel (A) pin 3 is now also at 50% PWM output | ||
| + | delay(1000); | ||
| + | pwmReset(); //all pins are disconnected from their channels and no longer outputting the PWM signal | ||
| + | | ||
| + | } | ||
| + | |||
| + | // the loop routine runs over and over again forever: | ||
| + | void loop() { | ||
| + | |||
| + | } | ||
| + | </code> | ||