From 5ddfb5e266ea00366df869f64e9e8525add0b141 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Mon, 8 May 2023 00:04:32 +0300 Subject: [PATCH] fixed unwanted offset bug --- software/GToE/GToE.ino | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/software/GToE/GToE.ino b/software/GToE/GToE.ino index eda4bd7..98b535c 100644 --- a/software/GToE/GToE.ino +++ b/software/GToE/GToE.ino @@ -48,7 +48,6 @@ int playingModes[6]; //actual channel modes array updated from channels each bea int pulsePeriod; bool isPlaying = false; -bool beatCounted = false; bool pulseCounted = false; unsigned int tickCount = 0; @@ -123,7 +122,7 @@ void setup() { display.setTextColor(SSD1306_WHITE); display.println(F("V:0.1a")); //Version display.display(); - delay(1200); + delay(800); updateScreen(); updateTiming(); @@ -151,23 +150,36 @@ void clock() { tickCount++; } else { tickCount = 0; - if (pulseCount < PPQN) { + if (pulseCount < (PPQN-1)) { //-1 is here to avoid extra IF to reset to 0 pulseCount++; - beatCounted = false; //reset pulse and beat count AFTER the pulse is incremented - pulseCounted = false; } else { - pulseCount = 0; //Beat happens here + pulseCount = 0; } } + //pulse and beat count reset + if (tickCount == 0) { + pulseCounted = false; + } + + // pull low all outputs after set pulse length + if (tickCount >= PULSE_LENGTH) { + for (int i = 0; i<6; i++) { + digitalWrite(outsPins[i], LOW); + } + } + } } void sendTriggers() { //divider - if (pulseCount == 0 && !beatCounted) { + if (pulseCount == 0) { for (int i = 0; i<6; i++) { - playingModes[i] = clockModes[channels[i].mode]; //updated here to prevent sync problems for multipliers + if (playingModes[i] != clockModes[channels[i].mode]) { //switching modes on the beat and resetting channel clock + 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) { @@ -181,7 +193,6 @@ void sendTriggers() { } } } - beatCounted = true; } //multiplier @@ -192,7 +203,7 @@ void sendTriggers() { digitalWrite(outsPins[i], HIGH); } } - if (outsClocksCounts[i] < (PPQN / abs(playingModes[i])) - 1) { + if (playingModes[i] < 0 && outsClocksCounts[i] < (PPQN / abs(playingModes[i])) - 1) { //multiplier outsClocksCounts[i]++; } else { outsClocksCounts[i] = 0;