Set timer to start and stop program #4

Closed
opened 2023-08-22 13:15:58 -05:00 by W1CDN · 10 comments
Owner

Calling a "program" anything you want to schedule for the future, like "n minutes on, m minutes off, with this message."

  • Enter start/stop/duration into webform
  • #3 in the middle

Once RTC chip gets here, this will get more complex.

See https://github.com/contrem/arduino-timer as referenced in #3.

Calling a "program" anything you want to schedule for the future, like "n minutes on, m minutes off, with this message." - Enter start/stop/duration into webform - #3 in the middle Once RTC chip gets here, this will get more complex. See https://github.com/contrem/arduino-timer as referenced in #3.
W1CDN added the
enhancement
label 2023-08-22 13:15:58 -05:00
Author
Owner

I wrote some code and then tested it. The problem with arduino-timer is that it (as it is supposed to) doesn't block, or at least I can't make it.

Here is an idea: https://github.com/contrem/arduino-timer/discussions/53#discussioncomment-1269463

timer.every(shortestNoteLength, continuePlayingMySong);

In this example, continuePlayingMySong() would increment (internally?) and then know what it was supposed to be doing. So in terms of K, it would be something like
111010111 for timing, with 1 being gpio on and 0 being off.

Maybe increments would look like this example?

size_t repeat_count = 1;
bool repeat_x_times(void *opaque) {
  size_t limit = (size_t)opaque;

  Serial.print("repeat_x_times: ");
  Serial.print(repeat_count);
  Serial.print("/");
  Serial.println(limit);

  return ++repeat_count <= limit; // remove this task after limit reached
}
// call the repeat_x_times function every 1000 millis (1 second)
  timer.every(1000, repeat_x_times, (void *)10);

I am also looking at other timing libraries; this one might not be the best for this part of the project.

I wrote some code and then tested it. The problem with arduino-timer is that it (as it is supposed to) doesn't block, or at least I can't make it. Here is an idea: https://github.com/contrem/arduino-timer/discussions/53#discussioncomment-1269463 `timer.every(shortestNoteLength, continuePlayingMySong);` In this example, `continuePlayingMySong()` would increment (internally?) and then know what it was supposed to be doing. So in terms of `K`, it would be something like `111010111` for timing, with 1 being gpio on and 0 being off. Maybe increments would look like this example? ``` size_t repeat_count = 1; bool repeat_x_times(void *opaque) { size_t limit = (size_t)opaque; Serial.print("repeat_x_times: "); Serial.print(repeat_count); Serial.print("/"); Serial.println(limit); return ++repeat_count <= limit; // remove this task after limit reached } ``` ``` // call the repeat_x_times function every 1000 millis (1 second) timer.every(1000, repeat_x_times, (void *)10); ``` **I am also looking at other timing libraries; this one might not be the best *for this part* of the project.**
Author
Owner

To summarize, there are a few places where timers are needed:

  • to start/stop sending anything at all at the beginning/end of the event/race
  • to start/stop sending a defined message at the beginning of the "on" cycle
  • to start/stop sending each character in a message (dit and dah)

For the first two, arduino-timer.h looks really useful.

For the last (which I need to code first), it looks like I can do one of these

  • use millis() to track time inside a function with while
  • use a library like Switch_lib
    • might need to modify to use milliseconds directly
  • use another library
To summarize, there are a few places where timers are needed: - to start/stop sending anything at all at the beginning/end of the event/race - to start/stop sending a defined message at the beginning of the "on" cycle - to start/stop sending each character in a message (dit and dah) For the first two, `arduino-timer.h` looks really useful. For the last (which I need to code first), it looks like I can do one of these - use `millis()` to track time inside a function with `while` - not sure if this will work or not - "And note - you do not use "while" loops in any program that requires multi-tasking - doing more than one thing at a time. And "delay()" is itself, a while loop, so you cannot use that." https://forum.arduino.cc/t/millis-and-while-loop/615016/5 - use a library like `Switch_lib` - might need to modify to use milliseconds directly - use another library
Author
Owner
Maybe stop trying to reinvent the wheel. - https://github.com/ggoraa/MorsDuino - https://github.com/milador/EasyMorse uses delay() - https://github.com/markfickett/arduinomorse looks neat - https://github.com/imfrancisd/MorseCodeMachine uses delay() - https://github.com/DefProc/lewis can also listen, a little more complex - https://charlesreid1.com/wiki/Arduino/Morse_Library - https://github.com/ridencww/cww_MorseTx uses delay() - https://github.com/etherkit/MorseArduino allegedly doesn't block https://github.com/etherkit/MorseArduino/issues/1, but I can't get it to work at all - https://search.arduino.cc/search?tab=reference&q=morse more to look at - https://github.com/jandelgado/jled looks neat, haven't tried
Author
Owner

Found a bunch I couldn't make work.

Telegraph works, but uses delay(). Sigh. https://git.kj7rrv.com/kj7rrv/Telegraph/src/branch/main/Telegraph.cpp

ETA: This might be OK. The webserver is asynchronous, so I'm able to enter a new value into the webform to control whether the message sends, and it gets caught in if() on the next loop(). You just can't (yet) stop the message in the middle, but for this application you would have to wait less than a minute at most.

Unless you want it running continuously for training, hmm. Weighing the perfect and the good here.

Found a bunch I couldn't make work. Telegraph works, but uses delay(). Sigh. https://git.kj7rrv.com/kj7rrv/Telegraph/src/branch/main/Telegraph.cpp ETA: This might be OK. The webserver is asynchronous, so I'm able to enter a new value into the webform to control whether the message sends, and it gets caught in `if()` on the next `loop()`. You just can't (yet) stop the message in the middle, but for this application you would have to wait less than a minute at most. Unless you want it running continuously for training, hmm. Weighing the perfect and the good here.
Author
Owner

Errors in arduinomorse:
image

Errors in arduinomorse: ![image](/attachments/c4e56300-7d14-46d7-8229-92d8a7768a48)
252 KiB
Author
Owner

JLED looks like a winner! I can start and stop sending midstream from the webui.

Sometimes it stops with the LED on, so will need to fix that.

JLED looks like a winner! I can start and stop sending midstream from the webui. Sometimes it stops with the LED on, so will need to fix that.
Author
Owner

This issue has gotten a bit muddled, but I will note that as of 3977971341, I can control whether a gpio/LED is sending a Morse message or not from the web UI.

use #3 to discuss sending code

use this issue to discuss scheduling program start

This issue has gotten a bit muddled, but I will note that as of 39779713415f553833cc20805401087171900b2a, I can control whether a gpio/LED is sending a Morse message or not from the web UI. # use #3 to discuss sending code # use this issue to discuss scheduling program start
mattbk changed title from Set timer to start and stop keying radio to Set timer to start and stop program 2023-08-31 09:51:36 -05:00
Author
Owner

Closed in #24.

Closed in #24.
W1CDN closed this issue 2023-09-15 16:54:02 -05:00

Hi! I'm the developer of the Telegraph library. It looks like you found a solution, but if you ever want to use Telegraph but it doesn't do everything you'd need, feel free to submit an issue or PR on its repo. 73

Hi! I'm the developer of the Telegraph library. It looks like you found a solution, but if you ever want to use Telegraph but it doesn't do everything you'd need, feel free to submit an issue or PR on its repo. 73
Author
Owner

@kj7rr, thanks for the work you've done. I'll think about any changes I might make, but this whole codebase is pretty much me learning by breaking things!

@kj7rr, thanks for the work you've done. I'll think about any changes I might make, but this whole codebase is pretty much me learning by breaking things!
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: W1CDN/vulpes#4
No description provided.