In this example we use MegunoLink’s Interface Panel visualiser to create a user interface (UI) which updates three variables using a single serial message. The UI uses a button to package up the values from three number controls. The Arduino, using our Command Handler, processes the message and extracts out the values sent.
Downloads
This example is available as part of our Arduino Library but you can also download the MegunoLink interface and Arduino program here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
/* ************************************************************************ Single Message Multiple Parameters This program demonstrates how MegunoLink's Interface Panel and our command handler Arduino library can be used to update multiple variables using a single message. The example folder also contains a MegunoLink project, with an Interface Panel to update the variables. Visit: * http://www.MegunoLink.com to download MegunoLink. ************************************************************************ */ #include "MegunoLink.h" #include "CommandHandler.h" float a = 1; float b = 2; float c = 3; CommandHandler<> SerialCommandHandler; InterfacePanel MyInterface; void Cmd_GetValues(CommandParameter &Parameters) { Serial.println("\nSending values to interface."); MyInterface.SetNumber(F("a"), a); MyInterface.SetNumber(F("b"), b); MyInterface.SetNumber(F("c"), c); } void Cmd_SetValues(CommandParameter &Parameters) { Serial.print("\nUpdating values.."); a = Parameters.NextParameterAsDouble(); b = Parameters.NextParameterAsDouble(); c = Parameters.NextParameterAsDouble(); Serial.print(" a = "); Serial.print(a); Serial.print(" b = "); Serial.print(b); Serial.print(" c = "); Serial.println(c); } void setup() { Serial.begin(9600); delay(1000); Serial.println("Single Message Multiple Parameter Example"); Serial.println("------------------------------------------"); SerialCommandHandler.AddCommand(F("SetValues"), Cmd_SetValues); SerialCommandHandler.AddCommand(F("GetValues"), Cmd_GetValues); } void loop() { SerialCommandHandler.Process(); } |