From 06ef7b1ae7c22a0d31b05d397f5f4a1dc36e58f1 Mon Sep 17 00:00:00 2001 From: dfrencham Date: Mon, 5 Mar 2018 16:21:17 +1000 Subject: [PATCH 1/3] Makefile update --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 92dad75..5ed9d54 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ # Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile -MONITOR_PORT = /dev/ttyACM0 -#MONITOR_PORT = /dev/cu.wchusbserial1420 +MONITOR_PORT = /dev/cu.wchusbserial1420 BOARD_TAG = uno ARDUINO_DIR = /Applications/Arduino.app/Contents/Java ARDMK_DIR = /usr/local/opt/arduino-mk From f81bee836c92203eedbda6032cd3929c48487d65 Mon Sep 17 00:00:00 2001 From: dfrencham Date: Mon, 5 Mar 2018 16:22:56 +1000 Subject: [PATCH 2/3] Update .gitignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 414487d..211d5ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build-*/ +.vscode/ \ No newline at end of file From 79580f0e83edd0be1a41b2e0d303f015304a8a72 Mon Sep 17 00:00:00 2001 From: dfrencham Date: Tue, 6 Mar 2018 07:09:10 +1000 Subject: [PATCH 3/3] lawabb - timing updates --- AudioFX.cpp | 46 ++++++++----- AudioFX.h | 3 +- CHANGELOG.md | 76 +++++++++++----------- Gate.cpp | 14 ++-- LightTree.cpp | 52 +++++---------- LightTree.h | 9 ++- Makefile | 3 +- Sequence.cpp | 177 +++++++++++++++++++++++++++++++++++--------------- Sequence.h | 5 +- constants.h | 36 +++++----- rad-gate.ino | 51 ++++++--------- 11 files changed, 267 insertions(+), 205 deletions(-) mode change 100644 => 100755 AudioFX.cpp mode change 100644 => 100755 AudioFX.h mode change 100644 => 100755 CHANGELOG.md mode change 100644 => 100755 Gate.cpp mode change 100644 => 100755 LightTree.cpp mode change 100644 => 100755 LightTree.h mode change 100644 => 100755 Makefile mode change 100644 => 100755 Sequence.cpp mode change 100644 => 100755 Sequence.h mode change 100644 => 100755 constants.h mode change 100644 => 100755 rad-gate.ino diff --git a/AudioFX.cpp b/AudioFX.cpp old mode 100644 new mode 100755 index 910f8a3..bcda68d --- a/AudioFX.cpp +++ b/AudioFX.cpp @@ -28,11 +28,12 @@ AudioFX::AudioFX(JQ6500_Serial *jref) { } void AudioFX::start_tone(int hz) { - serial_print("Tone"); + // serial_print_val("Tone", TONE_DROP_HZ); tone(PIN_SPEAKER, TONE_DROP_HZ); } void AudioFX::stop_tone() { + // serial_print("Tone Stop"); noTone(PIN_SPEAKER); } @@ -49,15 +50,18 @@ void AudioFX::play_sound_samples() { return; } - serial_print("Play Sample1"); - play_sample(SFX_PREP,2013); + serial_print("Play 1.mp3"); + play_sample(SFX_PREP); // try this first. If use below + // play_sample(SFX_PREP,2013); // file_number, play_time delay(1750); - serial_print("Play Sample2"); - play_sample(SFX_WATCH_GATE,2330); - serial_print("SFX Done"); + serial_print("Play 2.mp3"); + play_sample(SFX_WATCH_GATE); + //play_sample(SFX_WATCH_GATE,2330); // file_number, play_time + serial_print("SFX mp3 play Done"); } void AudioFX::play_abort() { + serial_print("playing abort tones"); tone(PIN_SPEAKER, TONE_ABORT_1_HZ, DELAY_ABORT_TONE_1_MS); delay(DELAY_ABORT_TONE_1_MS); tone(PIN_SPEAKER, TONE_ABORT_2_HZ, DELAY_ABORT_TONE_2_MS); @@ -65,7 +69,7 @@ void AudioFX::play_abort() { void AudioFX::play_sample(uint8_t track) { if (SFX_ADAFRUIT) { - serial_print("SFX playing on Adafruit device"); + serial_print("a. SFX playing on Adafruit device"); sfx->playTrack(track); delay(50); while (digitalRead(PIN_SFX_ACT) == LOW) { @@ -79,33 +83,43 @@ void AudioFX::play_sample(uint8_t track) { // We need to use the method below (passing in playtime) to // finish playing when the track finishes. It is a crap way to do // it, but for $3 for a JQ6500, I can live with it. - serial_print("SFX playing on QJ6500 device"); + serial_print("a. SFX playing on JQ6500 device"); jfx->playFileByIndexNumber(track); - delay(50); - while(jfx->getStatus() == MP3_STATUS_PLAYING) + delay(150); + byte stat =jfx->getStatus(); //0x00 , 0x01, 0x02 Stopped/Playing/Paused + serial_print_val("SFX getStatus()",stat); + while(stat != MP3_STATUS_STOPPED) { - // wait for sample to finish + // waiting for mp3 to finish // debug - //serial_print_val("SFX Status",jfx->getStatus()); + delay(150); + serial_print_val("SFX getStatus()",stat); } serial_print("SFX done"); } - return; + // return; } // needed for JQ6500, because cheap crap. void AudioFX::play_sample(uint8_t track, int playTime) { if (SFX_ADAFRUIT) { - serial_print("SFX playing on Adafruit device"); + serial_print("b. SFX playing on Adafruit device"); sfx->playTrack(track); delay(playTime); } else { - serial_print("SFX playing on QJ6500 device"); + serial_print("b. SFX playing on JQ6500 device"); jfx->playFileByIndexNumber(track); delay(playTime); } serial_print("SFX done"); - return; + // return; } + +void AudioFX::stop_play() { + // may need to test status first + serial_print("Pausing JQ6500 device"); + jfx->pause(); + +} diff --git a/AudioFX.h b/AudioFX.h old mode 100644 new mode 100755 index d522378..1a49d2b --- a/AudioFX.h +++ b/AudioFX.h @@ -20,6 +20,7 @@ class AudioFX { void play_sound_samples(); void play_abort(); void play_power_on(); + void stop_play(); private: Adafruit_Soundboard *sfx; @@ -28,4 +29,4 @@ class AudioFX { void play_sample(uint8_t track, int playTime); }; -#endif +#endif diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 index b55444c..13344ce --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,37 +1,39 @@ -# Change Log - -## 0.7.5 -- fixed gate abort interrupt - -## 0.7.4 -- fixed spelling error in function name - -## 0.7.3 -- Added mode for controlling relay based light trees - -## 0.7.2 -- Fixed light tree sequence for cheap NeoPixel stick clones (they seem to use reverse order addressing) - -## 0.7.1 -- Changed pin assignments to improve circuit board layout - -## 0.7.0 -- Removed Volume library entirely, added trim pot to design -- switched from relay board to MOSFET - -## 0.6.0 -- Changed Volume library for Volume3 -- Fixed issues with JCQ500 library support -- Added schematic - -## 0.5.1 -- Added JQ6500 sound module support -- Added RGB light tree support - -## 0.5.0 -- Fixed C++ bug around object declarations - -## 0.4.0 -- Refactored from C to C++ -- Added makefile -- Released to git hub +# Change Log +## 0.8.0b +- timing support + +## 0.7.5 +- fixed gate abort interrupt + +## 0.7.4 +- fixed spelling error in function name + +## 0.7.3 +- Added mode for controlling relay based light trees + +## 0.7.2 +- Fixed light tree sequence for cheap NeoPixel stick clones (they seem to use reverse order addressing) + +## 0.7.1 +- Changed pin assignments to improve circuit board layout + +## 0.7.0 +- Removed Volume library entirely, added trim pot to design +- switched from relay board to MOSFET + +## 0.6.0 +- Changed Volume library for Volume3 +- Fixed issues with JCQ500 library support +- Added schematic + +## 0.5.1 +- Added JQ6500 sound module support +- Added RGB light tree support + +## 0.5.0 +- Fixed C++ bug around object declarations + +## 0.4.0 +- Refactored from C to C++ +- Added makefile +- Released to git hub diff --git a/Gate.cpp b/Gate.cpp old mode 100644 new mode 100755 index 576b2cb..0cd651f --- a/Gate.cpp +++ b/Gate.cpp @@ -19,8 +19,8 @@ void Gate::random_wait() { int rand_delay = random(DELAY_RAND_MIN,DELAY_RAND_MAX+1); unsigned long wait_timer = millis() + rand_delay; serial_print_val("Gate sequence random wait time",rand_delay); - serial_print_val("Wait timer",wait_timer); - serial_print_val("Millis",millis()); + // serial_print_val("Wait timer",wait_timer); + // serial_print_val("Millis",millis()); while((millis() < wait_timer) && (!FLAG_ABORT_PENDING)) { // waiting for random wait to finish } @@ -33,9 +33,8 @@ void Gate::ready(){ } void Gate::arm() { - // set LED to red - // turn on electro magnet - // beep + serial_print("Gate Deactivate"); + digitalWrite(PIN_RELAY, LOW); } void Gate::abort() { @@ -43,7 +42,8 @@ void Gate::abort() { } void Gate::drop() { - digitalWrite(PIN_RELAY, LOW); + serial_print("Gate Activate"); + digitalWrite(PIN_RELAY, HIGH); } bool Gate::is_sequence_running() { @@ -65,4 +65,4 @@ void Gate::set_sequence_running(bool running) { void Gate::set_abortable(bool abortable) { FLAG_IS_ABORTABLE = abortable; -} +} diff --git a/LightTree.cpp b/LightTree.cpp old mode 100644 new mode 100755 index 7c029b6..f6e7b1e --- a/LightTree.cpp +++ b/LightTree.cpp @@ -38,32 +38,17 @@ void LightTree::initialise(bool useRelays, int pin) { } } -void LightTree::light_set(int step, Gate* gate) { - serial_print_val("Set LED", step); - switch (step) { - case 1: - led_reset(); - modeRelay ? light_set_relay(step) : light_set_pixel(step); - break; - case 2: - case 3: - modeRelay ? light_set_relay(step) : light_set_pixel(step); - break; - case 4: - gate->drop(); - modeRelay ? light_set_relay(step) : light_set_pixel(step); - break; - default: - led_reset(); - } +void LightTree::light_set(int step) { + serial_print_val("Set LED ", step); + modeRelay ? light_set_relay(step) : light_set_pixel(step); } void LightTree::led_reset() { if (modeRelay) { - digitalWrite(PIN_LIGHT_TREE_RELAY_1, HIGH); - digitalWrite(PIN_LIGHT_TREE_RELAY_2, HIGH); - digitalWrite(PIN_LIGHT_TREE_RELAY_3, HIGH); - digitalWrite(PIN_LIGHT_TREE_RELAY_4, HIGH); + digitalWrite(PIN_LIGHT_TREE_RELAY_1, LOW); + digitalWrite(PIN_LIGHT_TREE_RELAY_2, LOW); + digitalWrite(PIN_LIGHT_TREE_RELAY_3, LOW); + digitalWrite(PIN_LIGHT_TREE_RELAY_4, LOW); } else { for(int i=0;i<8;i++) { _strip.setPixelColor(i,0,0,0,0); @@ -74,12 +59,10 @@ void LightTree::led_reset() { void LightTree::abort() { if (modeRelay) { - //digitalWrite(PIN_LIGHT_TREE_RELAY_1, HIGH); - //led_reset(); - digitalWrite(PIN_LIGHT_TREE_RELAY_1, HIGH); - digitalWrite(PIN_LIGHT_TREE_RELAY_2, LOW); - digitalWrite(PIN_LIGHT_TREE_RELAY_3, LOW); - digitalWrite(PIN_LIGHT_TREE_RELAY_4, HIGH); + digitalWrite(PIN_LIGHT_TREE_RELAY_1, LOW); + digitalWrite(PIN_LIGHT_TREE_RELAY_2, HIGH); + digitalWrite(PIN_LIGHT_TREE_RELAY_3, HIGH); + digitalWrite(PIN_LIGHT_TREE_RELAY_4, LOW); } else { led_reset(); for(int i=0;i<8;i++) { @@ -105,7 +88,6 @@ void LightTree::set_status(uint32_t color) { _strip.show(); } - void LightTree::light_set_pixel(int step) { switch (step) { case 1: @@ -154,18 +136,18 @@ void LightTree::light_set_pixel(int step) { void LightTree::light_set_relay(int step) { switch (step) { case 1: - digitalWrite(PIN_LIGHT_TREE_RELAY_1, LOW); + digitalWrite(PIN_LIGHT_TREE_RELAY_1, HIGH); break; case 2: - digitalWrite(PIN_LIGHT_TREE_RELAY_2, LOW); + digitalWrite(PIN_LIGHT_TREE_RELAY_2, HIGH); break; case 3: - digitalWrite(PIN_LIGHT_TREE_RELAY_3, LOW); + digitalWrite(PIN_LIGHT_TREE_RELAY_3, HIGH); break; case 4: - digitalWrite(PIN_LIGHT_TREE_RELAY_4, LOW); + digitalWrite(PIN_LIGHT_TREE_RELAY_4, HIGH); break; - default: + default: led_reset(); } -} \ No newline at end of file +} diff --git a/LightTree.h b/LightTree.h old mode 100644 new mode 100755 index 555e63e..1c0ec77 --- a/LightTree.h +++ b/LightTree.h @@ -5,7 +5,6 @@ #include #include "utility.h" -#include "Gate.h" #ifndef _LIGHTREE_H #define _LIGHTREE_H @@ -17,17 +16,17 @@ class LightTree { LightTree(); void initialise(bool useRelays, int pin); - void light_set(int step, Gate* gate); + void light_set(int step); void led_reset(); void abort(); void ready(); void set_status(uint32_t color); - + private: Adafruit_NeoPixel _strip; void light_set_pixel(int step); void light_set_relay(int step); - + }; -#endif +#endif diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 5ed9d54..92dad75 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ # Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile -MONITOR_PORT = /dev/cu.wchusbserial1420 +MONITOR_PORT = /dev/ttyACM0 +#MONITOR_PORT = /dev/cu.wchusbserial1420 BOARD_TAG = uno ARDUINO_DIR = /Applications/Arduino.app/Contents/Java ARDMK_DIR = /usr/local/opt/arduino-mk diff --git a/Sequence.cpp b/Sequence.cpp old mode 100644 new mode 100755 index ec143bd..2e4ac65 --- a/Sequence.cpp +++ b/Sequence.cpp @@ -2,96 +2,136 @@ * RemoteArDuino (RAD) Gate * (c) Danny Frencham 2017 *****************************************/ + /************************************************** + Action Plan for the latter part of sequence + + ItemTime(ms)Action1 Action2 Action3 + 0 0 Set LED1 Play Tone 632 + 1 60 Stop Tone + 2 120 Set LED2 Play Tone 632 + 3 180 Stop Tone + 4 240 Set LED3 Play Tone 632 + 5 300 Stop Tone + 6 360 Set LED4 Play Tone 632 Gate Activate + 7 660 Gate Deactivate + 8 2610 Reset LEDS Stop Tone + *****************************************************/ #include "constants.h" #include "utility.h" #include "Sequence.h" +volatile long sensor_time = 0; +unsigned long gate_drop_start = 0; +volatile bool gotInterrupt2 = false; +extern void end_seq(volatile long react_time); + Sequence::Sequence(Gate* gateOb, AudioFX* audioOb, LightTree* lighttreeOb) { gate = gateOb; audio = audioOb; lighttree = lighttreeOb; + pinMode(PIN_SENSOR, INPUT_PULLUP); +} + +void Interrupt2() { + if (gotInterrupt2 == false) { + gotInterrupt2 = true; + sensor_time = millis() - gate_drop_start; + end_seq(sensor_time); + } } void Sequence::begin_sequence() { + + int T0 = 0; + int T1 = T0 + DELAY_DROP_TONE_MS; + int T2 = T1 + DELAY_INTERVAL_MS; + int T3 = T2 + DELAY_DROP_TONE_MS; + int T4 = T3 + DELAY_INTERVAL_MS; + int T5 = T4 + DELAY_DROP_TONE_MS; + int T6 = T5 + DELAY_INTERVAL_MS; + int T7 = T6 + GATE_ACTIVE_MS; + int T8 = T6 + DELAY_DROP_TONE_FINAL_MS; + + int target[] = {T0, T1, T2, T3, T4, T5, T6, T7, T8}; - // gate timings - // Tone Play Time, wait length, light tree step - gate_step gate_steps[] = { - { DELAY_DROP_TONE_MS, 0, 1 }, - { 0, 60, 0 }, - { DELAY_DROP_TONE_MS, 0, 2 }, - { 0, 60, 0 }, - { DELAY_DROP_TONE_MS, 0, 3 }, - { 0, 60, 0 }, - { DELAY_DROP_TONE_FINAL_MS, 0, 4 }, - { 0, 0, 0 } - }; + int seq[][3] = { + { 1, 1,-1}, + {-1, 0,-1}, + { 2, 1,-1}, + {-1, 0,-1}, + { 3 ,1,-1}, + {-1, 0,-1}, + { 4, 1, 1}, + {-1,-1, 0}, + {-1, 0,-1}, + }; + + int count = 9; + int step = 0; + unsigned long offset; + unsigned long now = 0; + int val; serial_print("Sequence begin"); gate->set_sequence_running(true); - int step = 0; - int playing_tone = 0; - int waiting = 0; - unsigned long timer_start = 0; - int gate_step_count = 7; // can't programatically count dynamic array - digitalWrite(LED_BUILTIN, HIGH); // turn on LED - digitalWrite(PIN_LED_ACTIVE, HIGH); // turn on LED + digitalWrite(LED_BUILTIN, HIGH); // turn on builtin LED + digitalWrite(PIN_LED_ACTIVE, HIGH); // turn on "Active" LED lighttree->led_reset(); audio->play_sound_samples(); gate->random_wait(); + // once the sequence starts, do not allow abort serial_print("No longer abortable"); - gate->set_abortable(false); // once the sequence starts, do not allow abort - while((step < gate_step_count) && (!gate->is_aborted())) { - unsigned long now = millis(); - unsigned long timer = now - timer_start; - - if (playing_tone && (timer >= gate_steps[step].tone_length)) { - // reset timer - playing_tone = 0; - serial_print_val("Stop tone",step); - serial_print_val("Tone length",gate_steps[step].tone_length); - audio->stop_tone(); - step++; - } - if (!playing_tone && (gate_steps[step].tone_length > 0)) { - timer_start = now; - audio->start_tone(TONE_DROP_HZ); - serial_print_val("LED step",step); - lighttree->light_set(gate_steps[step].light_num, gate); - playing_tone = 1; - } - if (waiting && (timer >= gate_steps[step].wait_length)) { - waiting = 0; - step++; - } - if (!waiting && (gate_steps[step].wait_length > 0)) { - timer_start = now; - waiting = 1; + gate->set_abortable(false); + + // Use interrupt to catch END request from SENSOR + attachInterrupt(digitalPinToInterrupt(PIN_SENSOR), Interrupt2, LOW); + + offset = millis(); + + while((step < count) && (!gate->is_aborted())) { + while (target[step] > now) { + now = millis() - offset; + } + for (int i=0; i<3; i++){ + val = seq[step][i]; + + if (val >= 0){ + if (i == 0){ + setLed(val); + } + if (i == 1){ + playTone(val); + } + if (i == 2){ + gateAct(val); + } + } } - gate->set_sequence_running(false); + step++; } + + serial_print("Setting sequence to STOP"); gate->set_sequence_running(false); if (!gate->is_aborted()) { audio->stop_tone(); } - else - { + else { abort_seq(); gate->set_abortable(true); } + set_ready(); digitalWrite(PIN_LED_ACTIVE, LOW); digitalWrite(LED_BUILTIN, LOW); - digitalWrite(PIN_RELAY, HIGH); // turn on magnet - serial_print("Sequence complete"); + serial_print("Sequence complete - Waiting for reaction time..."); } void Sequence::abort_seq() { @@ -107,3 +147,38 @@ void Sequence::set_ready() { lighttree->ready(); gate->ready(); } + +void Sequence::setLed(int val) { + // Serial.print("Set LED On = "); + // Serial.println(val); + lighttree->light_set(val); +} + +void Sequence::playTone(int val){ + // Serial.print("Play tone 632Hz = "); + // Serial.println(val); + if (val == 0) { + audio->stop_tone(); + } + else if (val == 1) { + audio->start_tone(TONE_DROP_HZ); + } +} + +void Sequence::gateAct(int val){ + // Serial.print("Gate activation = "); + // Serial.println(val); + if (val == 1) { + gate_drop_start = millis(); + gate->drop(); // turn on solenoid + gotInterrupt2 = false; + } + else if (val == 0) { + gate->arm(); // turn off solenoid + } +} + +void end_seq(volatile long react_time) { + serial_print_val("Reaction Time =", react_time); + serial_print("Press GO to restart..."); +} diff --git a/Sequence.h b/Sequence.h old mode 100644 new mode 100755 index f7caa1c..342582d --- a/Sequence.h +++ b/Sequence.h @@ -17,6 +17,9 @@ class Sequence { void begin_sequence(); void abort_seq(); void set_ready(); + void setLed(int led_val); + void gateAct(int gate_val); + void playTone(int play_val); private: Gate *gate; @@ -24,4 +27,4 @@ class Sequence { LightTree *lighttree; }; -#endif +#endif diff --git a/constants.h b/constants.h old mode 100644 new mode 100755 index fc5312c..00cb6cb --- a/constants.h +++ b/constants.h @@ -8,7 +8,7 @@ #include -#define VERSION "0.7.5" +#define VERSION "0.8.0" // uncomment for RGBW (for real Neopixels) //#define HARDWARE_NEOPIXEL_RGBW @@ -20,18 +20,20 @@ // set to "JQ6500" if using the cheap and friendly Aliexpress JQ6500 #define HARDWARE_SOUNDBOARD_JQ6500 1 -// some inferior gate controllers don't BEEP at the correct pitch -// frequence. Correct tones (in Hz) are below +#define DELAY_INTERVAL_MS 60 #define DELAY_DROP_TONE_MS 60 #define DELAY_DROP_TONE_FINAL_MS 2250 #define DELAY_GATE_RISE_WARN_MS 25 #define DELAY_ABORT_TONE_1_MS 220 #define DELAY_ABORT_TONE_2_MS 440 +#define GATE_ACTIVE_MS 300 // random start min and max #define DELAY_RAND_MIN 100 #define DELAY_RAND_MAX 2700 +// some inferior gate controllers don't BEEP at the correct pitch +// frequence. Correct tones (in Hz) are below #define TONE_DROP_HZ 632 #define TONE_GATE_RISE 1150 #define TONE_ABORT_1_HZ 740 @@ -39,19 +41,20 @@ #define TONE_VOLUME 130 #define PIN_NEO_PIXEL 13 // light tree pin -#define PIN_BUTTON_GO 2 -#define PIN_SPEAKER 11 -#define PIN_RELAY 8 // relay, or MOSFET -#define PIN_LED_ACTIVE 5 -#define PIN_GATE_STATUS_LED_RED 18 -#define PIN_GATE_STATUS_LED_GREEN 19 -#define PIN_SFX_TX 10 // sound board transmit -#define PIN_SFX_RX 9 // sound board receive +#define PIN_BUTTON_GO 2 // The GO/ABORT button -interrupt +#define PIN_SPEAKER 11 // tone output +#define PIN_RELAY 8 // relay, or MOSFET for GATE +#define PIN_LED_ACTIVE 5 // On when GO button activated +#define PIN_GATE_STATUS_LED_RED 18 // Not used +#define PIN_GATE_STATUS_LED_GREEN 19 //Not used +#define PIN_SFX_TX 10 // sound board transmit (Arduino Rx) +#define PIN_SFX_RX 9 // sound board receive (Arduino Tx) +#define PIN_SENSOR 3 // light sensor - interrupt #define PIN_SFX_RST 0 // sound board reset #define PIN_SFX_ACT 1 // sound board active -#define PIN_LIGHT_TREE_RELAY_ENABLE 3 +#define PIN_LIGHT_TREE_RELAY_ENABLE 4 #define PIN_LIGHT_TREE_RELAY_1 14 #define PIN_LIGHT_TREE_RELAY_2 15 #define PIN_LIGHT_TREE_RELAY_3 16 @@ -81,11 +84,4 @@ extern uint32_t RGB_WHITE; extern uint8_t SFX_PREP; extern uint8_t SFX_WATCH_GATE; -//struct gate_steps; -typedef struct { - unsigned long tone_length; - unsigned long wait_length; - int light_num; -} gate_step; - -#endif +#endif diff --git a/rad-gate.ino b/rad-gate.ino old mode 100644 new mode 100755 index e8bd791..bd3536c --- a/rad-gate.ino +++ b/rad-gate.ino @@ -6,7 +6,7 @@ /******************************************** * Notes: * To use relays for light control, ground - * pin 3. + * pin 4. * Relays should be connected to A0,A1,A2,A3 *********************************************/ @@ -28,39 +28,36 @@ bool buttonPressed = 0; AudioFX audioFX = AudioFX(&sfx); #endif #ifdef HARDWARE_SOUNDBOARD_JQ6500 - JQ6500_Serial mp3(PIN_SFX_TX,PIN_SFX_RX); + JQ6500_Serial mp3(PIN_SFX_TX, PIN_SFX_RX); AudioFX audioFX = AudioFX(&mp3); #endif Gate gate = Gate(); LightTree lighttree = LightTree(); -Sequence sequence = Sequence(&gate,&audioFX,&lighttree); +Sequence sequence = Sequence(&gate, &audioFX, &lighttree); unsigned long lastButtonPress = 0; -// interrrupt handler +// interrupt handler void Interrupt1() { if (gate.is_sequence_running()) { if ((millis() - lastButtonPress) > 1000) { - serial_print("Interrupt triggered - button press"); + // serial_print("Interrupt1 triggered - button press"); if (gate.is_abortable()) { - serial_print_val("Interrupt triggered - abort request received",(millis() - lastButtonPress)); + serial_print_val("Interrupt1 triggered - abort request received", (millis() - lastButtonPress)); + // audioFX.stop_play(); lighttree.abort(); gate.abort(); } - else { - serial_print("Interrupt triggered - abort request ignored"); - } - } - else { - serial_print("Interrupt ignored - button press"); } } } + void setup() { Serial.begin(19200); + serial_print(VERSION); #ifdef HARDWARE_SOUNDBOARD_ADAFRUIT ss.begin(9600); @@ -83,20 +80,23 @@ void setup() { //pinMode(PIN_REED_SWITCH, INPUT_PULLUP); pinMode(PIN_LIGHT_TREE_RELAY_ENABLE, INPUT_PULLUP); - // not working? not needed? + // Use interrupt to catch ABORT request from GO button attachInterrupt(digitalPinToInterrupt(PIN_BUTTON_GO), Interrupt1, HIGH); - digitalWrite(PIN_RELAY, HIGH); // turn on magnet + + // turn off solenoid + // serial_print("Gate solenoid DEACTIVATED"); + digitalWrite(PIN_RELAY, LOW); if (digitalRead(PIN_LIGHT_TREE_RELAY_ENABLE) == LOW) { lighttree.initialise(true, PIN_LIGHT_TREE_RELAY_ENABLE); - serial_print("Light tree configured for relay control"); - } else { + // serial_print("Light tree configured for relay control"); + } else { lighttree.initialise(false, PIN_NEO_PIXEL); serial_print("Light tree configured for serial control"); } serial_print("Gate controller initialised"); - serial_print(VERSION); + serial_print("Waiting for GO Button Press"); delay(100); lighttree.led_reset(); lighttree.ready(); @@ -109,24 +109,13 @@ void loop() { //serial_print("LOW"); buttonPressed = 0; // reset } - else if (digitalRead(PIN_BUTTON_GO) == HIGH) - { - serial_print("HIGH"); - if (gate.is_sequence_running()) { - serial_print("ABORT"); - lighttree.abort(); - gate.abort(); - lighttree.led_reset(); - } - else { - serial_print("SEQUENCE NOT RUNNING"); - } - // only fire the button press action once + else if (digitalRead(PIN_BUTTON_GO) == HIGH) { + serial_print("Button HIGH"); if (!buttonPressed) { buttonPressed = 1; lastButtonPress = millis(); serial_print_val("Sequence start - lastButtonPress val", lastButtonPress); sequence.begin_sequence(); - } // else still holding button + } } }