OOO
This commit is contained in:
commit
5ccc0ef4e5
3 changed files with 186 additions and 0 deletions
40
Out.cpp
Normal file
40
Out.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Out.cpp
|
||||
#include "Out.h"
|
||||
|
||||
Out::Out(unsigned byte pin) {
|
||||
pin = pin;
|
||||
state = LOW;
|
||||
|
||||
div = 1;
|
||||
cycle = 0;
|
||||
|
||||
dur = 0;
|
||||
width = 25;
|
||||
// this needs to dynamically change with width
|
||||
len = period * (width / 100);
|
||||
|
||||
pinMode(pin, OUTPUT);
|
||||
}
|
||||
|
||||
void Out::turnOn() {
|
||||
cycle += 1;
|
||||
if (cycle == div) {
|
||||
state = HIGH;
|
||||
digitalWrite(pin, state);
|
||||
dur = millis();
|
||||
|
||||
cycle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Out::turnOff() {
|
||||
if (state == HIGH && millis() - dur >= len) {
|
||||
state = LOW;
|
||||
digitalWrite(pin, state);
|
||||
dur = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Out::getState() {
|
||||
return state;
|
||||
}
|
||||
24
Out.h
Normal file
24
Out.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// Out.h
|
||||
#ifndef Out_h
|
||||
#define Out_h
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class Out {
|
||||
private:
|
||||
unsigned byte pin;
|
||||
unsigned char state;
|
||||
unsigned int div;
|
||||
unsigned int cycle;
|
||||
unsigned long dur;
|
||||
unsigned byte width;
|
||||
unsigned long len;
|
||||
|
||||
public:
|
||||
LED(unsigned byte pin);
|
||||
void turnOn();
|
||||
void turnOff();
|
||||
int getState();
|
||||
}
|
||||
|
||||
#endif
|
||||
122
master_clock.ino
Normal file
122
master_clock.ino
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <TimerOne.h>
|
||||
|
||||
#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;
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue