Working cycle example with hardcoded variables.

This commit is contained in:
mattbk 2023-09-09 12:53:34 -05:00
parent e706327623
commit 40baa679e1
2 changed files with 23 additions and 30 deletions

View File

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

View File

@ -57,7 +57,7 @@ bool yourProgramRunning;
bool yourProgramRunning_old; bool yourProgramRunning_old;
int step_length = 30000; // 30 secs int step_length = 30000; // 30 secs
int cycle_id = 1; // number of this transmitter in cycle 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) // HTML web page to handle 3 input fields (inputString, inputSend, inputFloat)
const char index_html[] PROGMEM = R"rawliteral( const char index_html[] PROGMEM = R"rawliteral(
@ -280,7 +280,6 @@ auto morseMOH =
JLed(keyer).UserFunc(&morseEffectMOH).DelayAfter(word_space_ms).Forever(); JLed(keyer).UserFunc(&morseEffectMOH).DelayAfter(word_space_ms).Forever();
auto morseMO5 = auto morseMO5 =
JLed(keyer).UserFunc(&morseEffectMO5).DelayAfter(word_space_ms).Forever(); 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 auto morseToSend = morseTEST; // set this up to overwrite later
// CW for blinker // CW for blinker
@ -296,12 +295,22 @@ auto morseMOH_blink =
JLed(blinker).UserFunc(&morseEffectMOH).DelayAfter(word_space_ms).Forever(); JLed(blinker).UserFunc(&morseEffectMOH).DelayAfter(word_space_ms).Forever();
auto morseMO5_blink = auto morseMO5_blink =
JLed(blinker).UserFunc(&morseEffectMO5).DelayAfter(word_space_ms).Forever(); 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 auto morseToSend_blink = morseTEST_blink; // set this up to overwrite later
// Cycle sequence placeholder // Cycle stuff
JLed morseToSend_sequence_blink[] = {morseToSend_blink, morseWait_blink}; auto morse_cycle = morseEffectMOS;
auto seq = JLedSequence(JLedSequence::eMode::SEQUENCE, morseToSend_sequence_blink).Forever(); 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 // 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 // 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 // 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 // Print current time and date
DateTime now = rtc.now(); // Get the current time DateTime now = rtc.now(); // Get the current time
char buff[] = "Alarm triggered at hh:mm:ss DDD, DD MMM YYYY"; char buff[] = "Alarm triggered at hh:mm:ss DDD, DD MMM YYYY";
@ -542,24 +551,8 @@ void loop() {
// Once alarm has started the program, set things up to run // Once alarm has started the program, set things up to run
if(yourProgramRunning == true){ if(yourProgramRunning == true){
Serial.println("Running program"); morses_sequence.Forever().Update();
// cycle instructions go here yourProgramRunning = false;
// 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();
yourProgramRunning = false;
} else } else
// See which message we are sending // See which message we are sending
// Only do this when the message has been updated. // Only do this when the message has been updated.
@ -601,16 +594,16 @@ void loop() {
morseToSend_blink.Update(); morseToSend_blink.Update();
// if you want to send cycle code and it is sending, keep sending // 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.Update();
//morseToSend_blink.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 // 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.Reset().Update();
//morseToSend_blink.Reset().Update(); //morseToSend_blink.Reset().Update();
seq.Update(); morses_sequence.Reset();
// if you don't want to send code // if you don't want to send code
} else { } else {