Compare commits

..

2 commits

View file

@ -45,6 +45,10 @@ unsigned long screenLastUpdate = 0;
const unsigned long screenThrottle = 200;
byte forceScreenUpdate = 1;
byte currentScreen = 0;
byte editMode = 0;
int mainScreenCursorPos = 0;
byte maxMainScreenPos = 8;
void setup() {
Serial.begin(9600);
@ -58,6 +62,7 @@ void setup() {
// screen setup
u8g2.begin();
u8g2.setFontMode(1);
// display.clearDisplay();
// display.setTextSize(2);
@ -150,16 +155,39 @@ void updateScreen() {
if (currentTime - screenLastUpdate >= screenThrottle && forceScreenUpdate == 1) {
screenLastUpdate = currentTime;
forceScreenUpdate = 0;
// The firstPage()/nextPage() loop manages where the drawing commands go
u8g2.firstPage();
do {
// --- Drawing Commands for the CURRENT Page ---
// All drawing commands must live INSIDE this do/while loop.
u8g2.setFont(u8g2_font_helvR08_tf);
u8g2.setCursor(0, 10);
u8g2.print(F("BPM: "));
u8g2.print(BPM); // Example of dynamic data
// 12px - nonbold
if (mainScreenCursorPos == 0) {
u8g2.setFont(u8g2_font_7x14B_mf);
} else {
u8g2.setFont(u8g2_font_7x14_mf);
}
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());
}
}
@ -187,10 +215,21 @@ void checkRPot() {
Serial.print("Encoder Position: ");
Serial.println(currentPos);
if (currentPos > previousPos) {
BPM++;
} else {
BPM--;
// on home screen
if (currentScreen == 0) {
if (editMode == 0) {
if (currentPos > previousPos) {
mainScreenCursorPos++;
if (mainScreenCursorPos > maxMainScreenPos) {
mainScreenCursorPos = 0;
}
} else {
mainScreenCursorPos--;
if (mainScreenCursorPos < 0) {
mainScreenCursorPos = maxMainScreenPos;
}
}
}
}
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() {
// The ISR should be as short and fast as possible
// Check the state of the DT pin to determine direction