Compare commits
No commits in common. "encoder-control-bpm" and "master" have entirely different histories.
encoder-co
...
master
1 changed files with 11 additions and 61 deletions
|
|
@ -45,10 +45,6 @@ unsigned long screenLastUpdate = 0;
|
||||||
const unsigned long screenThrottle = 200;
|
const unsigned long screenThrottle = 200;
|
||||||
byte forceScreenUpdate = 1;
|
byte forceScreenUpdate = 1;
|
||||||
|
|
||||||
byte currentScreen = 0;
|
|
||||||
byte editMode = 0;
|
|
||||||
int mainScreenCursorPos = 0;
|
|
||||||
byte maxMainScreenPos = 8;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
@ -62,7 +58,6 @@ void setup() {
|
||||||
|
|
||||||
// screen setup
|
// screen setup
|
||||||
u8g2.begin();
|
u8g2.begin();
|
||||||
u8g2.setFontMode(1);
|
|
||||||
|
|
||||||
// display.clearDisplay();
|
// display.clearDisplay();
|
||||||
// display.setTextSize(2);
|
// display.setTextSize(2);
|
||||||
|
|
@ -155,39 +150,16 @@ void updateScreen() {
|
||||||
if (currentTime - screenLastUpdate >= screenThrottle && forceScreenUpdate == 1) {
|
if (currentTime - screenLastUpdate >= screenThrottle && forceScreenUpdate == 1) {
|
||||||
screenLastUpdate = currentTime;
|
screenLastUpdate = currentTime;
|
||||||
forceScreenUpdate = 0;
|
forceScreenUpdate = 0;
|
||||||
|
// The firstPage()/nextPage() loop manages where the drawing commands go
|
||||||
u8g2.firstPage();
|
u8g2.firstPage();
|
||||||
do {
|
do {
|
||||||
// 12px - nonbold
|
// --- Drawing Commands for the CURRENT Page ---
|
||||||
if (mainScreenCursorPos == 0) {
|
// All drawing commands must live INSIDE this do/while loop.
|
||||||
u8g2.setFont(u8g2_font_7x14B_mf);
|
u8g2.setFont(u8g2_font_helvR08_tf);
|
||||||
} else {
|
u8g2.setCursor(0, 10);
|
||||||
u8g2.setFont(u8g2_font_7x14_mf);
|
|
||||||
}
|
|
||||||
|
|
||||||
u8g2.setCursor(0, 15);
|
|
||||||
u8g2.print(F("BPM: "));
|
u8g2.print(F("BPM: "));
|
||||||
u8g2.print(BPM);
|
u8g2.print(BPM); // Example of dynamic data
|
||||||
|
|
||||||
u8g2.setFont(u8g2_font_7x14_mf);
|
|
||||||
u8g2.setCursor(0, 45);
|
|
||||||
|
|
||||||
char buffer[5];
|
|
||||||
for (byte i = 1; i < 9; i++) {
|
|
||||||
if (i == 5) {
|
|
||||||
u8g2.setCursor(0, 60);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mainScreenCursorPos == i) {
|
|
||||||
u8g2.setFont(u8g2_font_7x14B_mf);
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(buffer, "[%d] ", i);
|
|
||||||
u8g2.print(buffer);
|
|
||||||
|
|
||||||
if (mainScreenCursorPos == i) {
|
|
||||||
u8g2.setFont(u8g2_font_7x14_mf);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} while (u8g2.nextPage());
|
} while (u8g2.nextPage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -215,21 +187,10 @@ void checkRPot() {
|
||||||
Serial.print("Encoder Position: ");
|
Serial.print("Encoder Position: ");
|
||||||
Serial.println(currentPos);
|
Serial.println(currentPos);
|
||||||
|
|
||||||
// on home screen
|
if (currentPos > previousPos) {
|
||||||
if (currentScreen == 0) {
|
BPM++;
|
||||||
if (editMode == 0) {
|
} else {
|
||||||
if (currentPos > previousPos) {
|
BPM--;
|
||||||
mainScreenCursorPos++;
|
|
||||||
if (mainScreenCursorPos > maxMainScreenPos) {
|
|
||||||
mainScreenCursorPos = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mainScreenCursorPos--;
|
|
||||||
if (mainScreenCursorPos < 0) {
|
|
||||||
mainScreenCursorPos = maxMainScreenPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
forceScreenUpdate = 1;
|
forceScreenUpdate = 1;
|
||||||
|
|
@ -241,17 +202,6 @@ void checkRPot() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleBPMChange(byte increase) {
|
|
||||||
if (increase == 1) {
|
|
||||||
BPM++;
|
|
||||||
} else {
|
|
||||||
BPM--;
|
|
||||||
}
|
|
||||||
|
|
||||||
period = (minute / BPM) / ppqn;
|
|
||||||
Timer1.setPeriod(period);
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateEncoder() {
|
void updateEncoder() {
|
||||||
// The ISR should be as short and fast as possible
|
// The ISR should be as short and fast as possible
|
||||||
// Check the state of the DT pin to determine direction
|
// Check the state of the DT pin to determine direction
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue