Before looking at how these are changed by the serial commands, lets look at how the command handler is setup. So the blinking rate will change when the OnTime and OffTime variables are changed. If it has been longer than the total amount of time the LED should be on and off, then LastBlink is reset so blinking continues.if the time since we last turned the led on ( LastBlink) is less than the amount of time the LED should be on then the LED is turned on, otherwise it it is turned off.It is responsible for turning the LED on and off.
The second block lives in the program loop. Changing these values will change the blink rate. The OnTime and OffTime variables are changed when we receive the serial commands !SetOnTime and !SetOffTime (more on that a bit later).
Void Cmd_SetOffTime(CommandParameter &Parameters) OnTime = Parameters.NextParameterAsInteger(OnTime) Void Cmd_SetOnTime(CommandParameter &Parameters) Void Cmd_ListAll(CommandParameter &Parameters) Check for serial commands and dispatch them. SerialCommandHandler.SetDefaultHandler(Cmd_Unknown) SerialCommandHandler.AddCommand(F("ListAll"), Cmd_ListAll) SerialCommandHandler.AddCommand(F("OffTime"), Cmd_SetOffTime) SerialCommandHandler.AddCommand(F("OnTime"), Cmd_SetOnTime) Setup the serial commands we can repond to Int OffTime = 100 // Amount of time the LED remains off Ĭonst int LEDPin = 13 // Pin the LED is attached to Int OnTime = 10 // Amount of time the LED remains on Long LastBlink = 0 // Time we last blinked the LED Implementing Command FunctionsĬommand functions are called by the SerialCommandHandler whenever it receives the registered command name.
#Serial terminal program arduino full#
Your Arduino sketch will print AddCommand: full if you try adding too many commands. Only 10 commands can be registered by default, but you can reserve space for more.
You can customize the command handler’s behavior by adding parameters between the ‘s. The command handler is a template so make sure to include the right after the CommandHandler type name. calls the registered function whenever it finds a command.reads serial messages and looks for commands.keeps track of the functions to call when a command is received.The global SerialCommandHandler looks after three things: