Set up scheduled program cycles #24
@@ -29,6 +29,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
AsyncWebServer server(80);
 | 
					AsyncWebServer server(80);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Assign output variables to GPIO pins
 | 
				
			||||||
 | 
					const int keyer = 32; //LED_BUILTIN for on-board (dev);//26 for LED; //32 for transmitter keyer
 | 
				
			||||||
 | 
					const int blinker = LED_BUILTIN;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RTC_DS3231 rtc; // set up RTC
 | 
					RTC_DS3231 rtc; // set up RTC
 | 
				
			||||||
const int alarmPin = 4; // pin to monitor for RTC alarms
 | 
					const int alarmPin = 4; // pin to monitor for RTC alarms
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -167,21 +171,6 @@ const char index_html[] PROGMEM = R"rawliteral(
 | 
				
			|||||||
  </script>
 | 
					  </script>
 | 
				
			||||||
</body></html>)rawliteral";
 | 
					</body></html>)rawliteral";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Assign output variables to GPIO pins
 | 
					 | 
				
			||||||
const int keyer = 32; //LED_BUILTIN for on-board (dev);//26 for LED; //32 for transmitter keyer
 | 
					 | 
				
			||||||
const int blinker = LED_BUILTIN;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Timers
 | 
					 | 
				
			||||||
//auto timer = timer_create_default();
 | 
					 | 
				
			||||||
Timer<1> timer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Example from https://github.com/contrem/arduino-timer#examples
 | 
					 | 
				
			||||||
bool toggle_led(void *) {
 | 
					 | 
				
			||||||
  //Serial.print("Timer time: ");
 | 
					 | 
				
			||||||
  //Serial.println(rtc.now().timestamp());
 | 
					 | 
				
			||||||
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
 | 
					 | 
				
			||||||
  return true; // keep timer active? true
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void notFound(AsyncWebServerRequest *request) {
 | 
					void notFound(AsyncWebServerRequest *request) {
 | 
				
			||||||
  request->send(404, "text/plain", "Not found");
 | 
					  request->send(404, "text/plain", "Not found");
 | 
				
			||||||
@@ -256,6 +245,15 @@ String processor(const String& var){
 | 
				
			|||||||
  return String();
 | 
					  return String();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Set up arduinomorse pin and default WPM
 | 
				
			||||||
 | 
					LEDMorseSender sender(blinker, 10.0f); // the 'f' makes sure this is a float
 | 
				
			||||||
 | 
					// TODO also for keyer once blinker works
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Timers
 | 
				
			||||||
 | 
					Timer<1> timer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//jled from https://github.com/jandelgado/jled/blob/master/examples/morse/morse_effect.h
 | 
					//jled from https://github.com/jandelgado/jled/blob/master/examples/morse/morse_effect.h
 | 
				
			||||||
class MorseEffect : public jled::BrightnessEvaluator {
 | 
					class MorseEffect : public jled::BrightnessEvaluator {
 | 
				
			||||||
    Morse morse_;
 | 
					    Morse morse_;
 | 
				
			||||||
@@ -379,7 +377,8 @@ JLedSequence* morses_sequence_blink_test = make_sequence(sequence, "MOE", 10, 10
 | 
				
			|||||||
void setup() {
 | 
					void setup() {
 | 
				
			||||||
  Serial.begin(115200);
 | 
					  Serial.begin(115200);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  
 | 
					  // Get arduinomorse ready to go
 | 
				
			||||||
 | 
					  sender.setup();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinMode(alarmPin, INPUT_PULLUP); // Set alarm pin as pullup
 | 
					  pinMode(alarmPin, INPUT_PULLUP); // Set alarm pin as pullup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -444,21 +443,27 @@ void setup() {
 | 
				
			|||||||
  if(yourInputMsg == 0){
 | 
					  if(yourInputMsg == 0){
 | 
				
			||||||
    morseToSend = morseTEST;
 | 
					    morseToSend = morseTEST;
 | 
				
			||||||
    morseToSend_blink = morseTEST_blink;
 | 
					    morseToSend_blink = morseTEST_blink;
 | 
				
			||||||
 | 
					    sender.setMessage(String("test test test de w1cdn  "));
 | 
				
			||||||
  } else if(yourInputMsg == 1){
 | 
					  } else if(yourInputMsg == 1){
 | 
				
			||||||
    morseToSend = morseMOE;
 | 
					    morseToSend = morseMOE;
 | 
				
			||||||
    morseToSend_blink = morseMOE_blink;
 | 
					    morseToSend_blink = morseMOE_blink;
 | 
				
			||||||
 | 
					    sender.setMessage(String("moe "));
 | 
				
			||||||
  } else if(yourInputMsg == 2){
 | 
					  } else if(yourInputMsg == 2){
 | 
				
			||||||
    morseToSend = morseMOI;
 | 
					    morseToSend = morseMOI;
 | 
				
			||||||
    morseToSend_blink = morseMOI_blink;
 | 
					    morseToSend_blink = morseMOI_blink;
 | 
				
			||||||
 | 
					    sender.setMessage(String("moi "));
 | 
				
			||||||
  } else if(yourInputMsg == 3){
 | 
					  } else if(yourInputMsg == 3){
 | 
				
			||||||
    morseToSend = morseMOS;
 | 
					    morseToSend = morseMOS;
 | 
				
			||||||
    morseToSend_blink = morseMOS_blink;
 | 
					    morseToSend_blink = morseMOS_blink;
 | 
				
			||||||
 | 
					    sender.setMessage(String("mos "));
 | 
				
			||||||
  } else if(yourInputMsg == 4){
 | 
					  } else if(yourInputMsg == 4){
 | 
				
			||||||
    morseToSend = morseMOH;
 | 
					    morseToSend = morseMOH;
 | 
				
			||||||
    morseToSend_blink = morseMOH_blink;
 | 
					    morseToSend_blink = morseMOH_blink;
 | 
				
			||||||
 | 
					    sender.setMessage(String("moh "));
 | 
				
			||||||
  } else if(yourInputMsg == 5){
 | 
					  } else if(yourInputMsg == 5){
 | 
				
			||||||
    morseToSend = morseMO5;
 | 
					    morseToSend = morseMO5;
 | 
				
			||||||
    morseToSend_blink = morseMO5_blink;
 | 
					    morseToSend_blink = morseMO5_blink;
 | 
				
			||||||
 | 
					    sender.setMessage(String("mo5 "));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  WiFi.mode(WIFI_STA);
 | 
					  WiFi.mode(WIFI_STA);
 | 
				
			||||||
@@ -584,13 +589,6 @@ void setup() {
 | 
				
			|||||||
      //}
 | 
					      //}
 | 
				
			||||||
      Serial.println(yourInputStartTimeUnix);
 | 
					      Serial.println(yourInputStartTimeUnix);
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      // We can't use arduino-timer for starting a program because 
 | 
					 | 
				
			||||||
      // it relies on millis(), which reset on power cycle.
 | 
					 | 
				
			||||||
      // timer.at(millis() + 10000, toggle_led);
 | 
					 | 
				
			||||||
      // Serial.println(millis());
 | 
					 | 
				
			||||||
      // auto active_tasks = timer.size();
 | 
					 | 
				
			||||||
      // Serial.println(active_tasks);
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
      // Use alarm built into RTC
 | 
					      // Use alarm built into RTC
 | 
				
			||||||
      rtc.setAlarm1(DateTime(yourInputStartTimeUnix), DS3231_A1_Date);
 | 
					      rtc.setAlarm1(DateTime(yourInputStartTimeUnix), DS3231_A1_Date);
 | 
				
			||||||
      //rtc.setAlarm1(DateTime(2020, 6, 25, 15, 34, 0), DS3231_A2_Date);
 | 
					      //rtc.setAlarm1(DateTime(2020, 6, 25, 15, 34, 0), DS3231_A2_Date);
 | 
				
			||||||
@@ -611,7 +609,7 @@ void loop() {
 | 
				
			|||||||
    // Timers
 | 
					    // Timers
 | 
				
			||||||
  timer.tick();
 | 
					  timer.tick();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  morses_sequence_blink_test->Forever().Update();
 | 
					  //morses_sequence_blink_test->Forever().Update();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 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.
 | 
				
			||||||
@@ -620,20 +618,26 @@ void loop() {
 | 
				
			|||||||
      if(yourInputMsg == 0){
 | 
					      if(yourInputMsg == 0){
 | 
				
			||||||
        morseToSend = morseTEST;
 | 
					        morseToSend = morseTEST;
 | 
				
			||||||
        morseToSend_blink = morseTEST_blink;
 | 
					        morseToSend_blink = morseTEST_blink;
 | 
				
			||||||
 | 
					        sender.setMessage(String("test test test de w1cdn "));
 | 
				
			||||||
      } else if(yourInputMsg == 1){
 | 
					      } else if(yourInputMsg == 1){
 | 
				
			||||||
        morseToSend = morseMOE;
 | 
					        morseToSend = morseMOE;
 | 
				
			||||||
 | 
					        sender.setMessage(String("moe "));
 | 
				
			||||||
        morseToSend_blink = morseMOE_blink;
 | 
					        morseToSend_blink = morseMOE_blink;
 | 
				
			||||||
      } else if(yourInputMsg == 2){
 | 
					      } else if(yourInputMsg == 2){
 | 
				
			||||||
        morseToSend = morseMOI;
 | 
					        morseToSend = morseMOI;
 | 
				
			||||||
 | 
					        sender.setMessage(String("moi "));
 | 
				
			||||||
        morseToSend_blink = morseMOI_blink;
 | 
					        morseToSend_blink = morseMOI_blink;
 | 
				
			||||||
      } else if(yourInputMsg == 3){
 | 
					      } else if(yourInputMsg == 3){
 | 
				
			||||||
        morseToSend = morseMOS;
 | 
					        morseToSend = morseMOS;
 | 
				
			||||||
 | 
					        sender.setMessage(String("mos "));
 | 
				
			||||||
        morseToSend_blink = morseMOS_blink;
 | 
					        morseToSend_blink = morseMOS_blink;
 | 
				
			||||||
      } else if(yourInputMsg == 4){
 | 
					      } else if(yourInputMsg == 4){
 | 
				
			||||||
        morseToSend = morseMOH;
 | 
					        morseToSend = morseMOH;
 | 
				
			||||||
 | 
					        sender.setMessage(String("moh "));
 | 
				
			||||||
        morseToSend_blink = morseMOH_blink;
 | 
					        morseToSend_blink = morseMOH_blink;
 | 
				
			||||||
      } else if(yourInputMsg == 5){
 | 
					      } else if(yourInputMsg == 5){
 | 
				
			||||||
        morseToSend = morseMO5;
 | 
					        morseToSend = morseMO5;
 | 
				
			||||||
 | 
					        sender.setMessage(String("mo5 "));
 | 
				
			||||||
        morseToSend_blink = morseMO5_blink;
 | 
					        morseToSend_blink = morseMO5_blink;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    // Keeps the key/led from locking up
 | 
					    // Keeps the key/led from locking up
 | 
				
			||||||
@@ -670,10 +674,14 @@ void loop() {
 | 
				
			|||||||
    //     blinker_continuous_wait
 | 
					    //     blinker_continuous_wait
 | 
				
			||||||
    // };
 | 
					    // };
 | 
				
			||||||
    // auto morses_sequence_blink = JLedSequence(JLedSequence::eMode::SEQUENCE, morses_blink);
 | 
					    // auto morses_sequence_blink = JLedSequence(JLedSequence::eMode::SEQUENCE, morses_blink);
 | 
				
			||||||
 | 
					    //morses_sequence_blink.Forever().Update();
 | 
				
			||||||
    morses_sequence_blink.Forever().Update();
 | 
					    Serial.println("Start sending");
 | 
				
			||||||
 | 
					    sender.startSending(); //arduinomorse
 | 
				
			||||||
    programRunning = true;
 | 
					    programRunning = true;
 | 
				
			||||||
    startProgram = false;
 | 
					    startProgram = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Serial.println(yourInputSend);
 | 
				
			||||||
 | 
					    // Serial.println(programRunning);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // if you want to send continuous code, and it's not sending, then start it up
 | 
					  // if you want to send continuous code, and it's not sending, then start it up
 | 
				
			||||||
@@ -688,26 +696,33 @@ 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) & (programRunning == true) &(morses_sequence_blink.Update() == true)){
 | 
					  } else if((yourInputSend == 2) & (programRunning == true)){//&(morses_sequence_blink.Update() == true)
 | 
				
			||||||
    morseToSend.Update();
 | 
					    //morseToSend.Update();
 | 
				
			||||||
    //morseToSend_blink.Update();
 | 
					    //morseToSend_blink.Update();
 | 
				
			||||||
    morses_sequence_blink.Update();
 | 
					    //morses_sequence_blink.Update();
 | 
				
			||||||
 | 
					    sender.continueSending();
 | 
				
			||||||
  // 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) & (programRunning == true) & (morses_sequence_blink.Update() == false)){
 | 
					  // } else if((yourInputSend == 2) & (programRunning == true) & !sender.continueSending()){//& (morses_sequence_blink.Update() == false)
 | 
				
			||||||
    morseToSend.Reset().Update();
 | 
					  //   //morseToSend.Reset().Update();
 | 
				
			||||||
    //morseToSend_blink.Reset().Update();
 | 
					  //   //morseToSend_blink.Reset().Update();
 | 
				
			||||||
    morses_sequence_blink.Reset();
 | 
					  //   //morses_sequence_blink.Reset();
 | 
				
			||||||
 | 
					  //   Serial.println("Start up cycle");
 | 
				
			||||||
 | 
					  //   sender.startSending();
 | 
				
			||||||
  // if the cycle program is not running
 | 
					  // if the cycle program is not running
 | 
				
			||||||
  } else if((yourInputSend == 2) & (programRunning == false)){
 | 
					  } else if((yourInputSend == 2) & (programRunning == false)){
 | 
				
			||||||
    morses_sequence_blink.Stop();
 | 
					    //Serial.println("Program is over, stop sending")
 | 
				
			||||||
 | 
					    //morses_sequence_blink.Stop();
 | 
				
			||||||
 | 
					    //sender.setMessage(String(""));
 | 
				
			||||||
  // if you don't want to send code
 | 
					  // if you don't want to send code
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
 | 
					    Serial.println("Stop sending");
 | 
				
			||||||
    // stop sending and make sure the pin is off
 | 
					    // stop sending and make sure the pin is off
 | 
				
			||||||
    morseToSend.Stop(JLed::eStopMode::FULL_OFF).Update();
 | 
					    morseToSend.Stop(JLed::eStopMode::FULL_OFF).Update();
 | 
				
			||||||
    morseToSend_blink.Stop(JLed::eStopMode::FULL_OFF).Update();
 | 
					    morseToSend_blink.Stop(JLed::eStopMode::FULL_OFF).Update();
 | 
				
			||||||
    morses_sequence_blink.Stop();
 | 
					    //morses_sequence_blink.Stop();
 | 
				
			||||||
 | 
					    sender.setMessage(String(""));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  //morseToSend.Update();
 | 
					  //morseToSend.Update();
 | 
				
			||||||
 | 
					  //sender.continueSending();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user