Update clock.h to support uClock v2.2.1 and implement external PPQN 4 #3

Merged
awonak merged 5 commits from refs/pull/3/head into main 2025-05-30 03:08:32 +00:00
3 changed files with 54 additions and 42 deletions
Showing only changes of commit ed3f8ec31f - Show all commits

View File

@ -19,6 +19,17 @@ Common directory locations:
* [Adafruit_GFX](https://github.com/adafruit/Adafruit-GFX-Library) [BSD] - Graphics helper library.
* [Adafruit_SSD1306](https://github.com/adafruit/Adafruit_SSD1306) [BSD] - Library for interacting with the SSD1306 OLED display.
> **NOTE:**
> The uClock library needs an additional build parameter passed in order to reduce the amount of dynamic memory it allocates. This can be done by modifying your `arduino.json` file and adding the following:
```json
"buildPreferences": [
["build.extra_flags" "-DEXT_INTERVAL_BUFFER_SIZE=1"]
]
```
For additional details, see: https://github.com/midilab/uClock/issues/53
## Example
Here's a trivial example showing some of the ways to interact with the library. This script rotates the active clock channel according to the set tempo. The encoder can change the temo or rotation direction. The play/pause button will toggle the clock activity on or off. The shift button will freeze the clock from advancing the channel rotation.
@ -111,3 +122,4 @@ void UpdateDisplay() {
gravity.display.display();
}
```

18
clock.h
View File

@ -29,8 +29,8 @@ class Clock {
void Init() {
// Initialize the clock library
uClock.init();
uClock.setMode(uClock.INTERNAL_CLOCK);
uClock.setPPQN(uClock.PPQN_96);
uClock.setClockMode(uClock.INTERNAL_CLOCK);
uClock.setOutputPPQN(uClock.PPQN_96);
uClock.setTempo(DEFAULT_TEMPO);
uClock.start();
}
@ -42,30 +42,30 @@ class Clock {
// Internal PPQN96 callback for all clock timer operations.
void AttachIntHandler(void (*callback)(uint32_t)) {
uClock.setOnPPQN(callback);
uClock.setOnOutputPPQN(callback);
}
// Set the source of the clock mode.
void SetSource(Source source) {
switch (source) {
case SOURCE_INTERNAL:
uClock.setMode(uClock.INTERNAL_CLOCK);
uClock.setClockMode(uClock.INTERNAL_CLOCK);
break;
case SOURCE_EXTERNAL_PPQN_24:
uClock.setMode(uClock.EXTERNAL_CLOCK);
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
case SOURCE_EXTERNAL_PPQN_4:
uClock.setMode(uClock.EXTERNAL_CLOCK);
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
default:
break;
}
}
bool ExternalSource() {
return uClock.getMode() == uClock.EXTERNAL_CLOCK;
return uClock.getClockMode() == uClock.EXTERNAL_CLOCK;
}
bool InternalSource() {
return uClock.getMode() == uClock.INTERNAL_CLOCK;
return uClock.getClockMode() == uClock.INTERNAL_CLOCK;
}
int Tempo() {
@ -85,7 +85,7 @@ class Clock {
}
bool IsPaused() {
return uClock.state == uClock.PAUSED;
return uClock.clock_state == uClock.PAUSED;
}
};