From d7bce9f7f6c4c9c2528a004c52468f01317aabf2 Mon Sep 17 00:00:00 2001 From: ocrdu Date: Mon, 16 Dec 2019 20:07:30 +0100 Subject: [PATCH] Added an example --- examples/flame/flame.ino | 18 ++++++++++++++++++ src/SAMD21turboPWM.cpp | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 examples/flame/flame.ino diff --git a/examples/flame/flame.ino b/examples/flame/flame.ino new file mode 100644 index 0000000..991eef6 --- /dev/null +++ b/examples/flame/flame.ino @@ -0,0 +1,18 @@ +// Uses two orange LEDS plus resistors on pins 4 and 7 (on the Nano 33 IoT; change for other boards). +// Don't pull more than 7mA from any pin. + +#include + +TurboPWM pwm; + +void setup() { + pwm.setClockDivider(1, false); + pwm.timer(1, 1, 1000, true); +} + +void loop() { + pwm.analogWrite(4, random(500, 1000)); + delay(25); + pwm.analogWrite(7, random(300, 1000)); + delay(25); +} diff --git a/src/SAMD21turboPWM.cpp b/src/SAMD21turboPWM.cpp index 7c95769..26755c5 100644 --- a/src/SAMD21turboPWM.cpp +++ b/src/SAMD21turboPWM.cpp @@ -61,7 +61,7 @@ int TurboPWM::timer(int timerNumber, unsigned int TCCDiv, unsigned long int sts, return 0; } - // Derive TCC prescaler from parameter TCCDiv; default to 4 + // Derive TCC prescaler from parameter TCCDiv; default to last known setting unsigned int my_TCC_CTRLA_PRESCALER_DIV; if (TCCDiv == 1) { my_TCC_CTRLA_PRESCALER_DIV = TCC_CTRLA_PRESCALER_DIV1_Val << TCC_CTRLA_PRESCALER_Pos;