-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix digitalWrite() - fix setFrequency() - add allOff() - add examples - update readme.md - minor refactor
- Loading branch information
1 parent
09a47d3
commit ec57d1b
Showing
11 changed files
with
486 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// FILE: PCA9685_allOFF_test.ino | ||
// AUTHOR: Rob Tillaart | ||
// DATE: 2020-11-22 | ||
// VERSION: 0.1.0 | ||
// PUPROSE: test PCA9685 library | ||
// | ||
|
||
/* | ||
sets all channels to a PWM | ||
then switches them all off | ||
you can check it by testing all channels. | ||
*/ | ||
|
||
#include "PCA9685.h" | ||
|
||
PCA9685 PCA(0x40); | ||
|
||
const uint8_t PIN = 2; | ||
|
||
void setup() | ||
{ | ||
Wire.begin(); | ||
PCA.begin(); | ||
|
||
Serial.begin(115200); | ||
Serial.print("PCA9685 LIB version: "); | ||
Serial.println(PCA9685_LIB_VERSION); | ||
Serial.println(); | ||
|
||
pinMode(PIN, INPUT_PULLUP); | ||
for (int channel = 0; channel < 16; channel++) | ||
{ | ||
PCA.setPWM(channel, 0, 1000); | ||
} | ||
delay(100); // to be sure they started. | ||
PCA.allOFF(); | ||
|
||
// delay(100); | ||
// PCA.reset(); // needed to reset the allOFF() | ||
// for (int channel = 0; channel < 16; channel++) | ||
// { | ||
// PCA.digitalWrite(channel, HIGH); | ||
// } | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
Serial.println(digitalRead(PIN)); // you can measure all pins | ||
} | ||
|
||
// -- END OF FILE -- |
66 changes: 66 additions & 0 deletions
66
examples/PCA9685_digitalWrite_test/PCA9685_digitalWrite_test.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// FILE: PCA9685_digitalWrite_test.ino | ||
// AUTHOR: Rob Tillaart | ||
// DATE: 2020-11-21 | ||
// VERSION: 0.1.0 | ||
// PUPROSE: test PCA9685 library | ||
// | ||
|
||
/* | ||
sets one channel to max PWM 0..4095 | ||
and connect the output to an interrupt pin 2 | ||
to see the frequency of the PWM | ||
*/ | ||
|
||
#include "PCA9685.h" | ||
|
||
PCA9685 PCA(0x40); | ||
|
||
const uint8_t IRQ_PIN = 2; | ||
volatile uint16_t count = 0; | ||
uint32_t lastTime = 0; | ||
|
||
void setup() | ||
{ | ||
Wire.begin(); | ||
PCA.begin(); | ||
|
||
Serial.begin(115200); | ||
Serial.print("PCA9685 LIB version: "); | ||
Serial.println(PCA9685_LIB_VERSION); | ||
Serial.println(); | ||
|
||
pinMode(IRQ_PIN, INPUT_PULLUP); | ||
attachInterrupt(digitalPinToInterrupt(IRQ_PIN), irq, CHANGE); | ||
|
||
// PCA.setPWM(15, 0, 1000); // works OK - reference to test irq() | ||
// PCA.digitalWrite(15, LOW); // works OK | ||
PCA.digitalWrite(15, HIGH); // works OK | ||
} | ||
|
||
|
||
// INTERRUPT ROUTINE TO COUNT THE PULSES | ||
void irq() | ||
{ | ||
count++; | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
uint32_t now = millis(); | ||
if (now - lastTime >= 1000) | ||
{ | ||
lastTime = now; | ||
// make a copy | ||
noInterrupts(); | ||
uint16_t t = count; | ||
count = 0; | ||
interrupts(); | ||
|
||
Serial.print(t); | ||
Serial.print("\t"); | ||
Serial.println(digitalRead(IRQ_PIN)); | ||
} | ||
} | ||
// -- END OF FILE -- |
Oops, something went wrong.