Compare commits
2 commits
master
...
encoder-co
| Author | SHA1 | Date | |
|---|---|---|---|
| 20281ad17a | |||
| 90693e8c2a |
1 changed files with 62 additions and 12 deletions
|
|
@ -45,6 +45,10 @@ 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);
|
||||||
|
|
@ -58,6 +62,7 @@ void setup() {
|
||||||
|
|
||||||
// screen setup
|
// screen setup
|
||||||
u8g2.begin();
|
u8g2.begin();
|
||||||
|
u8g2.setFontMode(1);
|
||||||
|
|
||||||
// display.clearDisplay();
|
// display.clearDisplay();
|
||||||
// display.setTextSize(2);
|
// display.setTextSize(2);
|
||||||
|
|
@ -150,16 +155,39 @@ 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 {
|
||||||
// --- Drawing Commands for the CURRENT Page ---
|
// 12px - nonbold
|
||||||
// All drawing commands must live INSIDE this do/while loop.
|
if (mainScreenCursorPos == 0) {
|
||||||
u8g2.setFont(u8g2_font_helvR08_tf);
|
u8g2.setFont(u8g2_font_7x14B_mf);
|
||||||
u8g2.setCursor(0, 10);
|
} else {
|
||||||
u8g2.print(F("BPM: "));
|
u8g2.setFont(u8g2_font_7x14_mf);
|
||||||
u8g2.print(BPM); // Example of dynamic data
|
}
|
||||||
|
|
||||||
|
u8g2.setCursor(0, 15);
|
||||||
|
u8g2.print(F("BPM: "));
|
||||||
|
u8g2.print(BPM);
|
||||||
|
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -187,10 +215,21 @@ void checkRPot() {
|
||||||
Serial.print("Encoder Position: ");
|
Serial.print("Encoder Position: ");
|
||||||
Serial.println(currentPos);
|
Serial.println(currentPos);
|
||||||
|
|
||||||
if (currentPos > previousPos) {
|
// on home screen
|
||||||
BPM++;
|
if (currentScreen == 0) {
|
||||||
} else {
|
if (editMode == 0) {
|
||||||
BPM--;
|
if (currentPos > previousPos) {
|
||||||
|
mainScreenCursorPos++;
|
||||||
|
if (mainScreenCursorPos > maxMainScreenPos) {
|
||||||
|
mainScreenCursorPos = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mainScreenCursorPos--;
|
||||||
|
if (mainScreenCursorPos < 0) {
|
||||||
|
mainScreenCursorPos = maxMainScreenPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forceScreenUpdate = 1;
|
forceScreenUpdate = 1;
|
||||||
|
|
@ -202,6 +241,17 @@ 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