Skip to content

Commit

Permalink
pause support
Browse files Browse the repository at this point in the history
  • Loading branch information
rabidaudio committed Jan 22, 2023
1 parent be4dd30 commit 075cbb6
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 18 deletions.
5 changes: 5 additions & 0 deletions clock/clock/clock.kicad_sch
Original file line number Diff line number Diff line change
Expand Up @@ -2898,6 +2898,11 @@
(effects (font (size 1.27 1.27)) (justify left bottom))
(uuid 43521de1-14fe-4507-9119-aadda0623aef)
)
(text "screw with spacer to panel at bottom\nbigger clock footprint\nmove regulator so more space for programmer\n"
(at 220.98 175.26 0)
(effects (font (size 1.27 1.27)) (justify left bottom))
(uuid 654b4b42-ce6d-4fce-86f0-5d93f93ee68d)
)
(text "mcu and programming pins" (at 54.61 194.31 0)
(effects (font (size 1.27 1.27)) (justify left bottom))
(uuid 8afc76ee-c334-4929-b5c2-a72687e79a26)
Expand Down
8 changes: 7 additions & 1 deletion clock/src/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Display
{
for (size_t i = 0; i < DIGITS; i++)
{
_digits[i].begin(portNumber, ctrlPins[i], i==1);
_digits[i].begin(portNumber, ctrlPins[i], i == 1);
setChar(i, ' ');
}
_index = 0;
Expand Down Expand Up @@ -86,6 +86,12 @@ class Display
}
}

void displayPaused()
{
clear();
setChar(1, '-');
}

// light up all segments (all 8's)
void displayReset()
{
Expand Down
30 changes: 30 additions & 0 deletions clock/src/PauseState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <Arduino.h>

class PauseState
{
private:
bool _paused = false;
bool _held = false;

public:
void setState(bool buttonsPressed)
{
if (!_held && buttonsPressed)
{
_paused = !_paused;
}
_held = buttonsPressed;
}

bool isPaused()
{
return _paused;
}

void reset()
{
_paused = false;
}
};
48 changes: 31 additions & 17 deletions clock/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Button.h"
#include "Timer.h"
#include "TapTempo.h"
#include "PauseState.h"

// Settings
// #define BACKPACK_DISPLAY 1
Expand Down Expand Up @@ -61,6 +62,7 @@ BufferedInput<16> cvInput;
TapTempo tapTempo;
RotaryEncoder knob;
Timer1 timer;
PauseState pauseState;

// Configure interrupts

Expand Down Expand Up @@ -131,51 +133,63 @@ void setup()
display.tick();
}

// On each loop:
// 1. handle the input state based on the buttons pressed
// 2. wait 10ms, updating the display the whole time
void loop()
{
uint16_t tapBpm = tapTempo.tick(cButton.isPressed());
bool aPressed = aButton.isPressed();
bool bPressed = bButton.isPressed();
bool cPressed = cButton.isPressed();
int8_t knobMotion = knob.readChanges();
timer.setBPMOffset(cvInput.read() / 2); // scale cvInput to 0-512 BPM
uint16_t tapBpm = tapTempo.tick(cPressed);
pauseState.setState(aPressed && bPressed);

if (aButton.isPressed() && bButton.isPressed())
if (aPressed && bPressed)
{
// Base reset, freeze clock and restart subdivisions
timer.reset();
tapTempo.cancel();
display.displayReset();
if (aButton.holdTime() >= FULL_RESET_TIME_MS && bButton.holdTime() >= FULL_RESET_TIME_MS)
{
// Full reset
timer.restoreDefaults();
pauseState.reset();
display.blinkReset();
}
}
else if (cButton.isPressed())
{
if (tapTempo.isActive())
{
timer.setBaseBPM(tapBpm);
display.displayNumber(tapBpm);
digitalWrite(LED_A_PIN, timer.clockOn() ? HIGH : LOW);
digitalWrite(LED_B_PIN, timer.subdivisionOn() ? HIGH : LOW);
}
}
else if (bButton.isPressed())
else if (aPressed)
{
uint8_t subdivisions = constrain(timer.getSubdivisions() + knobMotion, 1, 16);
timer.setSubdivisions(subdivisions);
display.displayNumber(subdivisions);
digitalWrite(LED_A_PIN, HIGH);
digitalWrite(LED_B_PIN, LOW);
}
else if (aButton.isPressed())
else if (bPressed)
{
int8_t swing = timer.getSwing() + knobMotion;
timer.setSwing(swing);
display.displayNumber(swing);
digitalWrite(LED_A_PIN, LOW);
digitalWrite(LED_B_PIN, HIGH);
}
else if (cPressed)
{
if (tapTempo.isActive())
{
timer.setBaseBPM(tapBpm);
display.displayNumber(tapBpm);
digitalWrite(LED_A_PIN, timer.clockOn() ? HIGH : LOW);
digitalWrite(LED_B_PIN, timer.subdivisionOn() ? HIGH : LOW);
}
}
else if (pauseState.isPaused())
{
// freeze clock and restart subdivisions
timer.reset();
tapTempo.cancel();
display.displayPaused();
}
else
{
uint16_t bpm = timer.getBaseBPM() + knobMotion;
Expand Down

0 comments on commit 075cbb6

Please sign in to comment.