forked from rabidaudio/synthesizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e3ae04
commit 92ede29
Showing
6 changed files
with
175 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,14 @@ | ||
# Clock | ||
|
||
## [Writeup and documentation](https://rabid.audio/projects/synth/clk/) | ||
|
||
- LED 7-segment display | ||
- Knob: continuous rotary selector | ||
- rotary encoder | ||
- Swing control | ||
- Out | ||
- subdivision out | ||
- LED blink on clock | ||
- Tap tempo | ||
- CV in | ||
|
||
|
||
States: | ||
Main State: | ||
- Display: current BPM (35-287) | ||
- Dots: show beats | ||
- knob: BPM | ||
- press button B: tap tempo | ||
|
||
swing control state (hold button A): | ||
- Display: swing amount (0-100%) | ||
- knob: swing amount | ||
|
||
Subdivision state (hold button B): | ||
- Display: number of subdivisions 1-16 | ||
- knob: controls subdivision amount | ||
|
||
Reset (hold both A and B): | ||
- Display: 000 | ||
- Freeze clock | ||
- Restart subdivisions | ||
|
||
Full Reset (hold both A and B for 2 seconds): | ||
- Display: blink 000 | ||
- Restart subdivisions | ||
- Restore default settings | ||
|
||
https://en.wikipedia.org/wiki/Swing_(jazz_performance_style) | ||
https://github.com/adafruit/TinyWireM/blob/master/USI_TWI_Master.h |
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,83 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
|
||
#define ROT_A bit(1) | ||
#define ROT_B bit(2) | ||
|
||
void enableInterrupts(pin) | ||
{ | ||
*digitalPinToPCMSK(pin) |= bit(digitalPinToPCMSKbit(pin)); // enable pin | ||
PCIFR |= bit(digitalPinToPCICRbit(pin)); // clear outstanding interrupt | ||
PCICR |= bit(digitalPinToPCICRbit(pin)); // enable interrupt for group | ||
} | ||
|
||
// A class for reading incremental rotary encoder rotations | ||
// and reporting changes using pin change interrupts. | ||
// Assumes pins are active low. | ||
class _RotaryEncoder | ||
{ | ||
private: | ||
uint8_t _aPin; | ||
uint8_t _bPin; | ||
bool _aState; | ||
bool _aPrevState; | ||
volatile int8_t _counter; | ||
|
||
public: | ||
void begin(aPin, bPin) | ||
{ | ||
_aPin = aPin; | ||
_bPin = bPin; | ||
_aState = 0; | ||
_aPrevState = 0; | ||
_counter = 0; | ||
pinMode(aPin, INPUT); | ||
pinMode(bPin, INPUT); | ||
// enable PC interrupts on each pin | ||
noInterrupts(); | ||
enableInterrupts(aPin); | ||
enableInterrupts(bPin); | ||
tick(); | ||
interrupts(); | ||
} | ||
|
||
void tick() | ||
{ | ||
_aPrevState = _aState; | ||
_aState = digitalRead(_aPin) == LOW; | ||
if (_aState != _aPrevState) { | ||
if (digitalRead(_bPin) == LOW) { | ||
_counter++; | ||
} else { | ||
_counter--; | ||
} | ||
} | ||
} | ||
|
||
// Compare the current state to where it was last and return the number | ||
// of turns that have happened since the last check. | ||
int8_t readChanges() | ||
{ | ||
int8_t v = _counter; | ||
_counter = 0; | ||
return v; | ||
} | ||
} | ||
|
||
// Global instance to assign | ||
_RotaryEncoder Knob; | ||
|
||
// Tick when PC interrupt is triggered | ||
|
||
ISR (PCINT0_vect) { | ||
Knob.tick(); | ||
} | ||
|
||
ISR (PCINT1_vect) { | ||
Knob.tick(); | ||
} | ||
|
||
ISR (PCINT2_vect) { | ||
Knob.tick(); | ||
} |
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
Oops, something went wrong.