Set up scheduled program cycles #24

Merged
W1CDN merged 41 commits from program-cycle into main 2023-09-15 16:51:45 -05:00
2 changed files with 23 additions and 30 deletions
Showing only changes of commit 40baa679e1 - Show all commits

View File

@ -21,7 +21,7 @@ lib_deps =
me-no-dev/AsyncTCP@^1.1.1
me-no-dev/ESP Async WebServer@^1.2.3
contrem/arduino-timer@^3.0.1
kj7rrv/Telegraph@^1.0.0
;kj7rrv/Telegraph@^1.0.0
jandelgado/JLed@^4.13.0
;adafruit/RTClib@^2.1.1
https://github.com/adafruit/RTClib.git ; >=2.1.2

View File

@ -57,7 +57,7 @@ bool yourProgramRunning;
bool yourProgramRunning_old;
int step_length = 30000; // 30 secs
int cycle_id = 1; // number of this transmitter in cycle
int n_transmitters = 5; //number of transmitters total
int n_transmitters = 2; //number of transmitters total
// HTML web page to handle 3 input fields (inputString, inputSend, inputFloat)
const char index_html[] PROGMEM = R"rawliteral(
@ -280,7 +280,6 @@ auto morseMOH =
JLed(keyer).UserFunc(&morseEffectMOH).DelayAfter(word_space_ms).Forever();
auto morseMO5 =
JLed(keyer).UserFunc(&morseEffectMO5).DelayAfter(word_space_ms).Forever();
auto morseWait = JLed(keyer).Off().Forever(); // set this up to overwrite later
auto morseToSend = morseTEST; // set this up to overwrite later
// CW for blinker
@ -296,12 +295,22 @@ auto morseMOH_blink =
JLed(blinker).UserFunc(&morseEffectMOH).DelayAfter(word_space_ms).Forever();
auto morseMO5_blink =
JLed(blinker).UserFunc(&morseEffectMO5).DelayAfter(word_space_ms).Forever();
auto morseWait_blink = JLed(blinker).Off().Forever(); // set this up to overwrite later
auto morseToSend_blink = morseTEST_blink; // set this up to overwrite later
// Cycle sequence placeholder
JLed morseToSend_sequence_blink[] = {morseToSend_blink, morseWait_blink};
auto seq = JLedSequence(JLedSequence::eMode::SEQUENCE, morseToSend_sequence_blink).Forever();
// Cycle stuff
auto morse_cycle = morseEffectMOS;
int period = morse_cycle.Period();
int repeats = step_length / period;
int remainder_wait = step_length - (period * repeats);
int total_wait = ((step_length * (n_transmitters - 1) + remainder_wait));
JLed morses[] = {
// WOW it looks like you can't do Repeat() and DelayAfter() at the same time?
// Opened https://github.com/jandelgado/jled/issues/122
JLed(blinker).UserFunc(&morse_cycle).Repeat(repeats),
//JLed(blinker).FadeOn(1000).Repeat(3)
JLed(blinker).Off(total_wait)
};
auto morses_sequence = JLedSequence(JLedSequence::eMode::SEQUENCE, morses);
//================================================================================
// start_program(): a function to start the planned program at the planned time
@ -528,7 +537,7 @@ void loop() {
// This statement from https://github.com/garrysblog/DS3231-Alarm-With-Adafruit-RTClib-Library/blob/master/DS3231-RTClib-Adafruit-Alarm-Poll-alarmFired/DS3231-RTClib-Adafruit-Alarm-Poll-alarmFired.ino
// Check if alarm by polling SQW alarm pin
if (yourInputSend == 2 & digitalRead(alarmPin) == LOW) {
if ((yourInputSend == 2) & (digitalRead(alarmPin) == LOW)) {
// Print current time and date
DateTime now = rtc.now(); // Get the current time
char buff[] = "Alarm triggered at hh:mm:ss DDD, DD MMM YYYY";
@ -542,23 +551,7 @@ void loop() {
// Once alarm has started the program, set things up to run
if(yourProgramRunning == true){
Serial.println("Running program");
// cycle instructions go here
// Experiment with timing
int repeats = step_length / morseEffectTEST.Period();
// add morseToSend once blink works
// add morseWait once blink works
// Send the message the right number of times
// put in the right message once this works
morseToSend_blink.UserFunc(&morseEffectTEST).DelayAfter(word_space_ms).Repeat(repeats);
// Wait the right amount of time
int remainder_wait = step_length - (morseEffectTEST.Period() * repeats);
int total_wait = ((step_length * (n_transmitters - 1) + remainder_wait));
morseWait_blink.Off().DelayAfter(total_wait);
// Set up sequence
JLed morseToSend_sequence_blink[] = {morseToSend_blink, morseWait_blink};
// fix the variable names through here, yikes
auto seq = JLedSequence(JLedSequence::eMode::SEQUENCE, morseToSend_sequence_blink).Forever().Update();
morses_sequence.Forever().Update();
yourProgramRunning = false;
} else
// See which message we are sending
@ -601,16 +594,16 @@ void loop() {
morseToSend_blink.Update();
// if you want to send cycle code and it is sending, keep sending
} else if((yourInputSend == 2) & (seq.Update() == true)){
} else if((yourInputSend == 2) & (morses_sequence.Update() == true)){
morseToSend.Update();
//morseToSend_blink.Update();
seq.Update();
morses_sequence.Update();
// if you want to send cycle code and it's not sending, then start it up
} else if((yourInputSend == 2) & (seq.Update() == false)){
} else if((yourInputSend == 2) & (morses_sequence.Update() == false)){
morseToSend.Reset().Update();
//morseToSend_blink.Reset().Update();
seq.Update();
morses_sequence.Reset();
// if you don't want to send code
} else {