Key radio as well as blinking LED #44

Merged
W1CDN merged 1 commits from key-radio into main 2023-09-15 21:19:51 -05:00
Showing only changes of commit ffb4163980 - Show all commits

View File

@ -27,7 +27,8 @@
AsyncWebServer server(80); AsyncWebServer server(80);
// Assign output variables to GPIO pins // Assign output variables to GPIO pins
const int keyer = 32; //LED_BUILTIN for on-board (dev);//26 for LED; //32 for transmitter keyer //LED_BUILTIN for ESP32 onboard LED, 32 for transmitter keyer
const int keyer = 32;
const int blinker = LED_BUILTIN; const int blinker = LED_BUILTIN;
RTC_DS3231 rtc; // set up RTC RTC_DS3231 rtc; // set up RTC
@ -63,9 +64,6 @@ bool programRunning;
int yourInputStepLength; int yourInputStepLength;
int yourInputCycleID; int yourInputCycleID;
int yourInputNtransmitters; int yourInputNtransmitters;
//int step_length = 10000; // 10 secs
//int cycle_id = 1; // number of this transmitter in cycle
//int n_transmitters = 2; //number of transmitters total
long start_millis = 0; long start_millis = 0;
long stop_millis = 0; long stop_millis = 0;
long pause_until_millis = 0; long pause_until_millis = 0;
@ -247,8 +245,8 @@ String processor(const String& var){
// Set up arduinomorse pin and default WPM // Set up arduinomorse pin and default WPM
LEDMorseSender sender(blinker, 10.0f) ; // the 'f' makes sure this is a float LEDMorseSender sender_blink(blinker, 10.0f) ; // the 'f' makes sure this is a float
// TODO also for keyer once blinker works LEDMorseSender sender_key(keyer, 10.0f) ; // the 'f' makes sure this is a float
// Speed is milliseconds per dit, which is 1000 * (60 / (50 * WPM)) // Speed is milliseconds per dit, which is 1000 * (60 / (50 * WPM))
// 60 is 20 wpm, 120 is 10 wpm, 90 is 15 wpm, etc. // 60 is 20 wpm, 120 is 10 wpm, 90 is 15 wpm, etc.
@ -264,7 +262,8 @@ void setup() {
Serial.begin(115200); Serial.begin(115200);
// Get arduinomorse ready to go // Get arduinomorse ready to go
sender.setup(); sender_blink.setup();
sender_key.setup();
pinMode(alarmPin, INPUT_PULLUP); // Set alarm pin as pullup pinMode(alarmPin, INPUT_PULLUP); // Set alarm pin as pullup
@ -297,10 +296,10 @@ void setup() {
// Initialize the output variables as outputs // Initialize the output variables as outputs
pinMode(keyer, OUTPUT); pinMode(keyer, OUTPUT);
//pinMode(blinker, OUTPUT); pinMode(blinker, OUTPUT);
// Set outputs to LOW // Set outputs to LOW
digitalWrite(keyer, LOW); digitalWrite(keyer, LOW);
//digitalWrite(blinker, LOW); digitalWrite(blinker, LOW);
// Initialize SPIFFS // Initialize SPIFFS
SPIFFS.begin(true); SPIFFS.begin(true);
@ -327,17 +326,23 @@ void setup() {
// On restart, keep doing what you were doing before // On restart, keep doing what you were doing before
yourInputMsg_old = yourInputMsg; yourInputMsg_old = yourInputMsg;
if(yourInputMsg == 0){ if(yourInputMsg == 0){
sender.setMessage(String("test test test de w1cdn ")); sender_blink.setMessage(String("test test test de w1cdn "));
sender_key.setMessage(String("test test test de w1cdn "));
} else if(yourInputMsg == 1){ } else if(yourInputMsg == 1){
sender.setMessage(String("moe ")); sender_blink.setMessage(String("moe "));
sender_key.setMessage(String("moe "));
} else if(yourInputMsg == 2){ } else if(yourInputMsg == 2){
sender.setMessage(String("moi ")); sender_blink.setMessage(String("moi "));
sender_key.setMessage(String("moi "));
} else if(yourInputMsg == 3){ } else if(yourInputMsg == 3){
sender.setMessage(String("mos ")); sender_blink.setMessage(String("mos "));
sender_key.setMessage(String("mos "));
} else if(yourInputMsg == 4){ } else if(yourInputMsg == 4){
sender.setMessage(String("moh ")); sender_blink.setMessage(String("moh "));
sender_key.setMessage(String("moh "));
} else if(yourInputMsg == 5){ } else if(yourInputMsg == 5){
sender.setMessage(String("mo5 ")); sender_blink.setMessage(String("mo5 "));
sender_key.setMessage(String("mo5 "));
} }
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
@ -392,17 +397,23 @@ void setup() {
// Check the message every time the form is submitted. // Check the message every time the form is submitted.
if(yourInputMsg == 0){ if(yourInputMsg == 0){
sender.setMessage(String("test test test de w1cdn ")); sender_blink.setMessage(String("test test test de w1cdn "));
sender_key.setMessage(String("test test test de w1cdn "));
} else if(yourInputMsg == 1){ } else if(yourInputMsg == 1){
sender.setMessage(String("moe ")); sender_blink.setMessage(String("moe "));
sender_key.setMessage(String("moe "));
} else if(yourInputMsg == 2){ } else if(yourInputMsg == 2){
sender.setMessage(String("moi ")); sender_blink.setMessage(String("moi "));
sender_key.setMessage(String("moi "));
} else if(yourInputMsg == 3){ } else if(yourInputMsg == 3){
sender.setMessage(String("mos ")); sender_blink.setMessage(String("mos "));
sender_key.setMessage(String("mos "));
} else if(yourInputMsg == 4){ } else if(yourInputMsg == 4){
sender.setMessage(String("moh ")); sender_blink.setMessage(String("moh "));
sender_key.setMessage(String("moh "));
} else if(yourInputMsg == 5){ } else if(yourInputMsg == 5){
sender.setMessage(String("mo5 ")); sender_blink.setMessage(String("mo5 "));
sender_key.setMessage(String("mo5 "));
} }
} }
// GET inputStepLength value on <ESP_IP>/get?inputStepLength=<inputMessage> // GET inputStepLength value on <ESP_IP>/get?inputStepLength=<inputMessage>
@ -497,26 +508,6 @@ void setup() {
void loop() { void loop() {
// See which message we are sending
// Only do this when the message has been updated.
// if(yourInputMsg != yourInputMsg_old){
// if(yourInputMsg == 0){
// sender.setMessage(String("test test test de w1cdn "));
// } else if(yourInputMsg == 1){
// sender.setMessage(String("moe "));
// } else if(yourInputMsg == 2){
// sender.setMessage(String("moi "));
// } else if(yourInputMsg == 3){
// sender.setMessage(String("mos "));
// } else if(yourInputMsg == 4){
// sender.setMessage(String("moh "));
// } else if(yourInputMsg == 5){
// sender.setMessage(String("mo5 "));
// }
// // Keeps the key/led from locking up
// yourInputMsg_old = yourInputMsg;
// }
// 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)) {
@ -542,33 +533,39 @@ void loop() {
// Subtract 2 rather than 1 here to account for start_millis duration at beginning of repeat. // Subtract 2 rather than 1 here to account for start_millis duration at beginning of repeat.
pause_until_millis = stop_millis + (yourInputStepLength * (yourInputNtransmitters - 2)); pause_until_millis = stop_millis + (yourInputStepLength * (yourInputNtransmitters - 2));
} }
//sender.startSending();
programRunning = true; programRunning = true;
startProgram = false; startProgram = false;
} }
// 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
if((yourInputSend == 1)){ if((yourInputSend == 1)){
if (!sender.continueSending()){ // If not sending, start sending. Yes, these need to be separate statements.
// Set the internal counters to the message's beginning. if (!sender_blink.continueSending()){
// Here, this results in repeating the message indefinitely. sender_blink.startSending();
sender.startSending(); }
if (!sender_key.continueSending()){
sender_key.startSending();
} }
// 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)){ } else if((yourInputSend == 2) & (programRunning == true)){
if((millis() < start_millis)){ if((millis() < start_millis)){
// Shut the pin off manually // Shut the pin off manually
digitalWrite(blinker, LOW); digitalWrite(blinker, LOW);
digitalWrite(keyer, LOW);
} else if((millis() >= start_millis) & (millis() <= stop_millis)){ } else if((millis() >= start_millis) & (millis() <= stop_millis)){
if (!sender.continueSending()){ // If not sending, start sending. Yes, these need to be separate statements
// Set the internal counters to the message's beginning. // for the blinker and keyer.
// Here, this results in repeating the message indefinitely. if (!sender_blink.continueSending()){
sender.startSending(); sender_blink.startSending();
}
if (!sender_key.continueSending()){
sender_key.startSending();
} }
} else if((millis() >= stop_millis) & (millis() <= pause_until_millis)){ } else if((millis() >= stop_millis) & (millis() <= pause_until_millis)){
// do nothing in this case -- in between cycles // do nothing in this case -- in between cycles
// Shut the pin off manually // Shut the pin off manually
digitalWrite(blinker, LOW); digitalWrite(blinker, LOW);
digitalWrite(keyer, LOW);
} else if((millis() >= pause_until_millis)){ } else if((millis() >= pause_until_millis)){
startProgram = true; startProgram = true;
} }
@ -577,9 +574,9 @@ void loop() {
// do we need something here? // do we need something here?
// if you don't want to send code // if you don't want to send code
} else if(yourInputSend == 0){ } else if(yourInputSend == 0){
//sender.setMessage(String("")) ; // Not sure this is the right way to stop things.
// Shut the pin off manually // Shut the pin off manually
digitalWrite(blinker, LOW); digitalWrite(blinker, LOW);
digitalWrite(keyer, LOW);
} }
} }