From 35c6f838c2eba52f9c3d2b0e43cdadacb8daa513 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Mon, 8 May 2023 00:29:01 +0300 Subject: [PATCH] switched to pulses per cycle, got rid of separate divider and multiplier --- software/GToE/GToE.ino | 46 +++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/software/GToE/GToE.ino b/software/GToE/GToE.ino index 98b535c..5c27dc5 100644 --- a/software/GToE/GToE.ino +++ b/software/GToE/GToE.ino @@ -42,7 +42,8 @@ channel channels[6] = { //array of channel settings { 8, 0, 0, 0 } }; -int outsClocksCounts[6]; +int channelPulseCount[6]; +int channelPulsesPerCycle[6]; int playingModes[6]; //actual channel modes array updated from channels each beat int pulsePeriod; @@ -91,7 +92,7 @@ const unsigned char splash_logo [] PROGMEM = { }; void setup() { - Serial.begin(9600); + //Serial.begin(9600); //check last bit in eeprom to know if settings were stored if (EEPROM.read(1023) == 'H') { @@ -173,42 +174,33 @@ void clock() { } void sendTriggers() { - //divider + //switching modes on the beat and resetting channel clock if (pulseCount == 0) { for (int i = 0; i<6; i++) { - if (playingModes[i] != clockModes[channels[i].mode]) { //switching modes on the beat and resetting channel clock + if (playingModes[i] != clockModes[channels[i].mode]) { playingModes[i] = clockModes[channels[i].mode]; - outsClocksCounts[i] = 0; - } - if (playingModes[i] > 0) { - if (outsClocksCounts[i] == 0) { //Pulse on 0 - if (channels[i].random == 0 || random(10) > channels[i].random) { - digitalWrite(outsPins[i], HIGH); - } - } - if (outsClocksCounts[i] < (playingModes[i] - 1)) { - outsClocksCounts[i]++; + if (playingModes[i] > 0) { + channelPulsesPerCycle[i] = (playingModes[i] * PPQN) - 1; } else { - outsClocksCounts[i] = 0; + channelPulsesPerCycle[i] = (PPQN / abs(playingModes[i])) - 1; } + channelPulseCount[i] = 0; } } } //multiplier for (int i = 0; i<6; i++) { - if (playingModes[i] < 0) { - if (outsClocksCounts[i] == 0) { //Pulse on 0 - if (channels[i].random == 0 || random(10) > channels[i].random) { //random - digitalWrite(outsPins[i], HIGH); - } + if (channelPulseCount[i] == 0) { //Pulse on 0 + if (channels[i].random == 0 || random(10) > channels[i].random) { //random + digitalWrite(outsPins[i], HIGH); } - if (playingModes[i] < 0 && outsClocksCounts[i] < (PPQN / abs(playingModes[i])) - 1) { //multiplier - outsClocksCounts[i]++; - } else { - outsClocksCounts[i] = 0; - } - } + } + if (channelPulseCount[i] < channelPulsesPerCycle[i]) { + channelPulseCount[i]++; + } else { + channelPulseCount[i] = 0; + } } } @@ -227,7 +219,7 @@ void updateTiming() { void resetClocks() { for (int i = 0; i<6; i++) { - outsClocksCounts[i] = 0; + channelPulseCount[i] = 0; digitalWrite(outsPins[i], LOW); //to avoid stuck leds } }