multiplication
This commit is contained in:
parent
019fe61f96
commit
7b6124ceda
4 changed files with 101 additions and 49 deletions
28
Out.cpp
28
Out.cpp
|
|
@ -7,7 +7,10 @@ Out::Out(byte pin) {
|
||||||
this->pin = pin;
|
this->pin = pin;
|
||||||
state = LOW;
|
state = LOW;
|
||||||
|
|
||||||
|
divideMode = 1;
|
||||||
|
modifier = 1;
|
||||||
div = 1;
|
div = 1;
|
||||||
|
divString = "";
|
||||||
cycle = 0;
|
cycle = 0;
|
||||||
|
|
||||||
dur = 0;
|
dur = 0;
|
||||||
|
|
@ -20,8 +23,6 @@ Out::Out(byte pin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Out::setLen(unsigned long currentPeriod) {
|
void Out::setLen(unsigned long currentPeriod) {
|
||||||
// Fix the integer division by using floating-point math temporarily
|
|
||||||
// The result 'len' is likely a duration in milliseconds, so keep it an integer type
|
|
||||||
len = (unsigned long)((double)currentPeriod * (width / 100.0) / 1000.0);
|
len = (unsigned long)((double)currentPeriod * (width / 100.0) / 1000.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,21 +41,36 @@ void Out::turnOn() {
|
||||||
void Out::turnOff() {
|
void Out::turnOff() {
|
||||||
|
|
||||||
if (state == HIGH && millis() - dur >= len) {
|
if (state == HIGH && millis() - dur >= len) {
|
||||||
Serial.println(len);
|
|
||||||
state = LOW;
|
state = LOW;
|
||||||
digitalWrite(pin, state);
|
digitalWrite(pin, state);
|
||||||
dur = 0;
|
dur = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Out::setDiv(int newDiv) {
|
void Out::setDiv(int modifier, byte divide = 1) {
|
||||||
div = newDiv;
|
if (divide == 1) {
|
||||||
|
div = ppqn * modifier;
|
||||||
|
divString = "/" + modifier;
|
||||||
|
} else {
|
||||||
|
div = ppqn / modifier;
|
||||||
|
divString = "x" + modifier;
|
||||||
|
}
|
||||||
|
divideMode = divide;
|
||||||
|
this->modifier = modifier;
|
||||||
};
|
};
|
||||||
|
|
||||||
void Out::setWidth(int newWidth) {
|
void Out::setWidth(int newWidth) {
|
||||||
|
Serial.println(modifier);
|
||||||
|
Serial.println(divideMode);
|
||||||
width = newWidth;
|
width = newWidth;
|
||||||
len = (unsigned long)((double)period * (width / 100.0) / 1000.0);
|
if (divideMode == 1) {
|
||||||
|
len = (unsigned long)((double)(minute / BPM) * (width / 100.0) / 1000.0);
|
||||||
|
} else {
|
||||||
|
len = (unsigned long)((double)(minute / BPM / modifier) * (width / 100.0) / 1000.0);
|
||||||
|
}
|
||||||
|
Serial.println(len);
|
||||||
|
|
||||||
|
Serial.println("=========");
|
||||||
};
|
};
|
||||||
|
|
||||||
int Out::getState() {
|
int Out::getState() {
|
||||||
|
|
|
||||||
10
Out.h
10
Out.h
|
|
@ -11,18 +11,20 @@ class Out {
|
||||||
int cycle;
|
int cycle;
|
||||||
unsigned long dur;
|
unsigned long dur;
|
||||||
unsigned long len;
|
unsigned long len;
|
||||||
|
byte width;
|
||||||
|
byte divideMode;
|
||||||
|
int div;
|
||||||
|
int modifier;
|
||||||
|
String divString;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Out(byte pin);
|
Out(byte pin);
|
||||||
void turnOn();
|
void turnOn();
|
||||||
void turnOff();
|
void turnOff();
|
||||||
void setLen(unsigned long currentPeriod);
|
void setLen(unsigned long currentPeriod);
|
||||||
void setDiv(int newDiv);
|
void setDiv(int newDiv, byte divide = 1);
|
||||||
void setWidth(int newWidth);
|
void setWidth(int newWidth);
|
||||||
int getState();
|
int getState();
|
||||||
byte width;
|
|
||||||
int div;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
44
globals.h
44
globals.h
|
|
@ -3,5 +3,49 @@
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
extern int BPM;
|
||||||
|
extern unsigned long minute;
|
||||||
extern unsigned long period;
|
extern unsigned long period;
|
||||||
|
extern byte ppqn;
|
||||||
#endif // GLOBALS_H
|
#endif // GLOBALS_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO:
|
||||||
|
|
||||||
|
PRE-DAC:
|
||||||
|
[ ] Figure out multiplicative beats X2 X4 X8 X16 X32?
|
||||||
|
[ ] Swing/Phase (same thing)
|
||||||
|
[ ] Probability
|
||||||
|
[ ] Humanization
|
||||||
|
[ ] Euclidian Rhythms
|
||||||
|
[ ] Steps - # of steps for a full pattern
|
||||||
|
[ ] Hits - how many hits across the steps, must be less than steps
|
||||||
|
[ ] Offset - move the starting point of the pattern
|
||||||
|
[ ] Logic (NO | AND | OR | XOR)
|
||||||
|
[ ] Mute
|
||||||
|
[ ] Save
|
||||||
|
[ ] Load
|
||||||
|
|
||||||
|
POST-DAC:
|
||||||
|
[ ] Different Wave Forms
|
||||||
|
[ ] Different Voltage levels
|
||||||
|
[ ] v/oct?
|
||||||
|
|
||||||
|
100BPM
|
||||||
|
4800BPM
|
||||||
|
|
||||||
|
POSSIBLE DIVISIONS:
|
||||||
|
1: x48
|
||||||
|
16: x32
|
||||||
|
32: x16
|
||||||
|
40: x8
|
||||||
|
44: x4
|
||||||
|
46: x2
|
||||||
|
---
|
||||||
|
48*1: 1 ** THIS NEEDS TO BE PASSED IN AS DIVIDE MODE
|
||||||
|
48*2 = 96: /2
|
||||||
|
48*4 = 192: /4
|
||||||
|
48*8 = /8
|
||||||
|
48*16 = /16
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <TimerOne.h>
|
#include <TimerOne.h>
|
||||||
#include "globals.h"
|
|
||||||
|
|
||||||
|
#include "globals.h"
|
||||||
#include "Out.h"
|
#include "Out.h"
|
||||||
|
|
||||||
#define SCREEN_WIDTH 128
|
#define SCREEN_WIDTH 128
|
||||||
|
|
@ -12,21 +12,17 @@
|
||||||
#define OLED_RESET -1
|
#define OLED_RESET -1
|
||||||
#define SCREEN_ADDRESS 0x3C
|
#define SCREEN_ADDRESS 0x3C
|
||||||
|
|
||||||
|
|
||||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
|
||||||
int BPM = 140;
|
byte play = 1;
|
||||||
unsigned long period = 60000000L / BPM;
|
int BPM = 100;
|
||||||
|
|
||||||
|
unsigned long minute = 60000000L;
|
||||||
|
byte ppqn = 96;
|
||||||
|
unsigned long period = (minute / BPM) / ppqn;
|
||||||
|
|
||||||
volatile boolean beatToggle = false;
|
volatile boolean beatToggle = false;
|
||||||
|
|
||||||
int clockDivCount = 0;
|
|
||||||
|
|
||||||
int mode = 0;
|
|
||||||
|
|
||||||
String modes[] = {
|
|
||||||
"CLK DIV"
|
|
||||||
};
|
|
||||||
|
|
||||||
Out out1(4);
|
Out out1(4);
|
||||||
Out out2(5);
|
Out out2(5);
|
||||||
Out out3(6);
|
Out out3(6);
|
||||||
|
|
@ -38,19 +34,16 @@ Out out8(11);
|
||||||
|
|
||||||
byte btnPin = 13;
|
byte btnPin = 13;
|
||||||
byte btnState = 0;
|
byte btnState = 0;
|
||||||
byte play = 1;
|
|
||||||
|
|
||||||
|
|
||||||
// the setup function runs once when you press reset or power the board
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(btnPin, INPUT_PULLUP);
|
pinMode(btnPin, INPUT_PULLUP);
|
||||||
|
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// init display
|
|
||||||
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
||||||
Serial.println(F("SSD1306 allocation failed"));
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
for (;;); // Don't proceed, loop forever
|
for (;;);
|
||||||
}
|
}
|
||||||
|
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
|
|
@ -62,10 +55,6 @@ void setup() {
|
||||||
String bpmCalculatedString = bpmString + BPM;
|
String bpmCalculatedString = bpmString + BPM;
|
||||||
display.println(bpmCalculatedString);
|
display.println(bpmCalculatedString);
|
||||||
|
|
||||||
// String modeString = "MODE: ";
|
|
||||||
// String currentModeString = modes[mode];
|
|
||||||
// display.println(modeString + currentModeString);
|
|
||||||
|
|
||||||
display.display();
|
display.display();
|
||||||
|
|
||||||
// init timer
|
// init timer
|
||||||
|
|
@ -73,6 +62,7 @@ void setup() {
|
||||||
Timer1.attachInterrupt(clock);
|
Timer1.attachInterrupt(clock);
|
||||||
Timer1.setPeriod(period);
|
Timer1.setPeriod(period);
|
||||||
|
|
||||||
|
// init outputs
|
||||||
out1.setLen(period);
|
out1.setLen(period);
|
||||||
out2.setLen(period);
|
out2.setLen(period);
|
||||||
out3.setLen(period);
|
out3.setLen(period);
|
||||||
|
|
@ -83,29 +73,29 @@ void setup() {
|
||||||
out8.setLen(period);
|
out8.setLen(period);
|
||||||
|
|
||||||
// manual setup
|
// manual setup
|
||||||
out1.setDiv(1);
|
out1.setDiv(8, 0);
|
||||||
out1.setWidth(25);
|
out1.setWidth(50);
|
||||||
|
|
||||||
out2.setDiv(2);
|
out2.setDiv(4, 0);
|
||||||
out2.setWidth(25);
|
out2.setWidth(50);
|
||||||
|
|
||||||
out3.setDiv(4);
|
out3.setDiv(2, 0);
|
||||||
out3.setWidth(25);
|
out3.setWidth(50);
|
||||||
|
|
||||||
out4.setDiv(8);
|
out4.setDiv(1);
|
||||||
out4.setWidth(25);
|
out4.setWidth(50);
|
||||||
|
|
||||||
out5.setDiv(16);
|
out5.setDiv(2);
|
||||||
out5.setWidth(25);
|
out5.setWidth(50);
|
||||||
|
|
||||||
out6.setDiv(32);
|
out6.setDiv(4);
|
||||||
out6.setWidth(25);
|
out6.setWidth(50);
|
||||||
|
|
||||||
out7.setDiv(64);
|
out7.setDiv(8);
|
||||||
out7.setWidth(25);
|
out7.setWidth(50);
|
||||||
|
|
||||||
out8.setDiv(1);
|
out8.setDiv(16);
|
||||||
out8.setWidth(10);
|
out8.setWidth(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clock(void) {
|
void clock(void) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue