Set up scheduled program cycles #24
|
@ -53,7 +53,11 @@ int yourInputMsg_old; // to save previous state and check changes
|
||||||
float yourInputFloat;
|
float yourInputFloat;
|
||||||
uint32_t yourInputTime; //to keep time
|
uint32_t yourInputTime; //to keep time
|
||||||
uint32_t yourInputStartTimeUnix;
|
uint32_t yourInputStartTimeUnix;
|
||||||
int yourProgramRunning;
|
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
|
||||||
|
|
||||||
// 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(
|
||||||
|
@ -276,6 +280,7 @@ 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
|
||||||
|
@ -291,14 +296,19 @@ 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
|
||||||
|
JLed morseToSend_sequence_blink[] = {morseToSend_blink, morseWait_blink};
|
||||||
|
auto seq = JLedSequence(JLedSequence::eMode::SEQUENCE, morseToSend_sequence_blink).Forever();
|
||||||
|
|
||||||
//================================================================================
|
//================================================================================
|
||||||
// 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
|
||||||
//================================================================================
|
//================================================================================
|
||||||
bool start_program(){
|
bool start_program(){
|
||||||
Serial.println("The scheduled program has started.");
|
Serial.println("The scheduled program has started.");
|
||||||
yourProgramRunning = 1;
|
yourProgramRunning = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +426,7 @@ void setup() {
|
||||||
yourInputSend = inputMessage.toInt();
|
yourInputSend = inputMessage.toInt();
|
||||||
// if not running a program, set the program running off
|
// if not running a program, set the program running off
|
||||||
if(yourInputSend != 2){
|
if(yourInputSend != 2){
|
||||||
yourProgramRunning = 0;
|
yourProgramRunning = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// GET inputWPM value on <ESP_IP>/get?inputWPM=<inputMessage>
|
// GET inputWPM value on <ESP_IP>/get?inputWPM=<inputMessage>
|
||||||
|
@ -523,12 +533,34 @@ void loop() {
|
||||||
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";
|
||||||
Serial.println(now.toString(buff));
|
Serial.println(now.toString(buff));
|
||||||
|
yourProgramRunning = true;
|
||||||
|
|
||||||
// Disable and clear alarm
|
// Disable and clear alarm
|
||||||
rtc.clearAlarm(1);
|
rtc.clearAlarm(1);
|
||||||
rtc.clearAlarm(2); // clear the other one just in case
|
rtc.clearAlarm(2); // clear the other one just in case
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
yourProgramRunning = false;
|
||||||
|
} 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.
|
||||||
if(yourInputMsg != yourInputMsg_old){
|
if(yourInputMsg != yourInputMsg_old){
|
||||||
|
@ -536,11 +568,6 @@ void loop() {
|
||||||
if(yourInputMsg == 0){
|
if(yourInputMsg == 0){
|
||||||
morseToSend = morseTEST;
|
morseToSend = morseTEST;
|
||||||
morseToSend_blink = morseTEST_blink;
|
morseToSend_blink = morseTEST_blink;
|
||||||
// Experiment with timing
|
|
||||||
int step_length = 30000; // 30 secs
|
|
||||||
int repeats = step_length / morseEffectTEST.Period();
|
|
||||||
morseToSend_blink.UserFunc(&morseEffectTEST).DelayAfter(word_space_ms).Repeat(repeats);
|
|
||||||
|
|
||||||
} else if(yourInputMsg == 1){
|
} else if(yourInputMsg == 1){
|
||||||
morseToSend = morseMOE;
|
morseToSend = morseMOE;
|
||||||
morseToSend_blink = morseMOE_blink;
|
morseToSend_blink = morseMOE_blink;
|
||||||
|
@ -574,14 +601,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) & (morseToSend.IsRunning() == true)){
|
} else if((yourInputSend == 2) & (seq.Update() == true)){
|
||||||
morseToSend.Update();
|
morseToSend.Update();
|
||||||
morseToSend_blink.Update();
|
//morseToSend_blink.Update();
|
||||||
|
seq.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) & (morseToSend.IsRunning() == false)){
|
} else if((yourInputSend == 2) & (seq.Update() == false)){
|
||||||
morseToSend.Reset().Update();
|
morseToSend.Reset().Update();
|
||||||
morseToSend_blink.Reset().Update();
|
//morseToSend_blink.Reset().Update();
|
||||||
|
seq.Update();
|
||||||
|
|
||||||
// if you don't want to send code
|
// if you don't want to send code
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user