#include #include #include #include #include #include "Out.h" #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); int BPM = 100; unsigned long period = 60000000L / BPM; volatile boolean beatToggle = false; int clockDivCount = 0; int mode = 0; String modes[] = { "CLK DIV" }; Out out1(2); Out out2(3); Out out3(4); Out out4(5); Out out5(6); Out out6(7); Out out7(8); Out out8(9); // the setup function runs once when you press reset or power the board void setup() { Serial.begin(9600); initDisp(); Timer1.initialize(1000000); Timer1.attachInterrupt(clock); Timer1.setPeriod(period); } void initDisp() { if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for (;;); // Don't proceed, loop forever } display.clearDisplay(); display.setTextSize(1.5); display.setTextColor(WHITE); display.setCursor(0, 0); String bpmString = "BPM: "; String bpmCalculatedString = bpmString + BPM; display.println(bpmCalculatedString); String modeString = "MODE: "; String currentModeString = modes[mode]; display.println(modeString + currentModeString); display.display(); } void clock(void) { beatToggle = true; } void loop() { if (beatToggle) { out1.turnOn(); beatToggle = false; } out1.turnOff(); } void clockDivider() { clockDivCount += 1; turnOnLed(0); if (clockDivCount % 2 == 0) { turnOnLed(1); }; if (clockDivCount % 3 == 0) { turnOnLed(2); }; if (clockDivCount % 4 == 0) { turnOnLed(3); }; if (clockDivCount % 8 == 0) { turnOnLed(4); }; if (clockDivCount % 16 == 0) { turnOnLed(5); }; if (clockDivCount % 32 == 0) { turnOnLed(6); }; if (clockDivCount % 64 == 0) { turnOnLed(6); }; if (clockDivCount == 64) { clockDivCount = 0; }; } }