Created
May 23, 2019 15:47
-
-
Save billautomata/96550178c55a3818fe31b3ca0500d4dd to your computer and use it in GitHub Desktop.
Revisions
-
billautomata created this gist
May 23, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ unsigned long BPM = 120; unsigned long PPQ = 24; unsigned long PPQ_T; unsigned long SECONDS_IN_MINUTE = 60; unsigned long MICROSECONDS_PER_PPQ = (SECONDS_IN_MINUTE * 1000000) / (BPM * PPQ); unsigned long _micros; unsigned long MICROSECONDS_PER_STEP = (SECONDS_IN_MINUTE * 1000000) / (BPM * 4); unsigned long STEP_T; bool isNoteOn; void setup() { Serial.begin(56000); PPQ_T = micros(); STEP_T = micros(); _micros = micros(); isNoteOn = false; } void loop() { _micros = micros(); if(_micros - PPQ_T >= MICROSECONDS_PER_PPQ) { PPQ_T = _micros; Serial.write((int)248); } if(_micros - STEP_T >= MICROSECONDS_PER_STEP) { STEP_T = _micros; if(isNoteOn == true) { Serial.write((uint8_t)128); // note OFF Serial.write((uint8_t)60); // note value Serial.write((uint8_t)64); // note velocity isNoteOn = false; } Serial.write((uint8_t)144); // note ON Serial.write((uint8_t)60); // note value Serial.write((uint8_t)64); // note velocity isNoteOn = true; } }