Hello,
I've been using Megunolink for a bit and have the buttons and numeric up downs figured.
Now I'm trying to use the check boxes and I'm having some issues getting the True or False signal into something the arduino can use.
Do you have to call Parameters.NextParameters() as a Boolean or am I comparing it to another const char.
I would appreciate any help.
Thanks
Alban
check box
Hi, there is a nifty trick you can do to achieve this. Just enter this as the expression for a particular checkbox (in this case called IPCheckBox1).
[IPCheckBox1.Checked ? "1" : "0"]
When evaluated it will return a 0 or 1 depending on its status.
Cheers
Phil
[IPCheckBox1.Checked ? "1" : "0"]
When evaluated it will return a 0 or 1 depending on its status.
Cheers
Phil
I'm a newbie as well. where do you put [IPCheckBox1.Checked ? "1" : "0"]? I'm placing this in the communications "on click send" text box. do we still need to put an Add varriable command in setup?
could you send a code example?
Thanks
griiker
Thanks
Hi Griiker, yes you will need to add something at the arduino end. Think of it like two separate parts. MegunoLink will construct the message you write into "on click send" and send it out the serial port. You then need to process that serial message at the Arduino end. This could be done yourself or by using our command handler library (which is included as part of the greater MegunoLink arduino library).
I recommend the command handler library approach. In that case you need to add an "!" and a "\r" to the end of your message.
So "on click send" will look something like this:
!SetBoolean [IPCheckBox1.Checked ? "1" : "0"]\r
Where SetBoolean is the command name.
At the arduino end id set it up more like this example
https://github.com/Megunolink/MLP/blob/ ... putPin.ino
You would add your command like this
SerialCommandHandler.AddCommand(F("SetBoolean"), Cmd_SetBoolean);
And add a function called Cmd_SetBoolean that looks like this:
void Cmd_SetBoolean(CommandParameter &Parameters)
{
Serial.print("Got new boolean:");
bool myboolean = (bool) Parameters.NextParameterAsInteger();
Serial.println(myboolean);
}
You could make myboolean a global variable so it can be used by other parts of your program.
Does this make sense?
Cheers
Phil
I recommend the command handler library approach. In that case you need to add an "!" and a "\r" to the end of your message.
So "on click send" will look something like this:
!SetBoolean [IPCheckBox1.Checked ? "1" : "0"]\r
Where SetBoolean is the command name.
At the arduino end id set it up more like this example
https://github.com/Megunolink/MLP/blob/ ... putPin.ino
You would add your command like this
SerialCommandHandler.AddCommand(F("SetBoolean"), Cmd_SetBoolean);
And add a function called Cmd_SetBoolean that looks like this:
void Cmd_SetBoolean(CommandParameter &Parameters)
{
Serial.print("Got new boolean:");
bool myboolean = (bool) Parameters.NextParameterAsInteger();
Serial.println(myboolean);
}
You could make myboolean a global variable so it can be used by other parts of your program.
Does this make sense?
Cheers
Phil
Thanks Philr
I'm not quite sure:
Serial.print("Got new boolean:");
is this supposed to show up in megulink monitor?
so if the megunolink is like this:
!SetBoolean [IPCheckBox1.Checked ? "1" : "0"]\r
will the myboolean be either a 1 of 0?
bool myboolean = (bool) Parameters.NextParameterAsInteger();
The thing I am trying to do is have one of 2 variables, 3 or 6, used as criteria. the user will use radio buttons to select either 3 or 6, and a sensor input will be compared to the chosen number.
Ill try this and see if it works.
Thanks
Griiker
I'm not quite sure:
Serial.print("Got new boolean:");
is this supposed to show up in megulink monitor?
so if the megunolink is like this:
!SetBoolean [IPCheckBox1.Checked ? "1" : "0"]\r
will the myboolean be either a 1 of 0?
bool myboolean = (bool) Parameters.NextParameterAsInteger();
The thing I am trying to do is have one of 2 variables, 3 or 6, used as criteria. the user will use radio buttons to select either 3 or 6, and a sensor input will be compared to the chosen number.
Ill try this and see if it works.
Thanks
Griiker
This bol isnt working.
I put in a function:
void Cmd_SetBoolean(CommandParameter &Parameters)
{
Serial.print("Got new boolean:");
bool paramselect = (bool) Parameters.NextParameterAsInteger();
Serial.println(paramselect);
}
and I made a global variable:
bool paramselect = 1;
the sketch is supposed to send the interface a 3.00 or a 6.00 and generate a graph, neither of which is happening. Before I tried doing this, I had the chart working. now nothing. when i click on the radio button for 6, it sets the boolean variable to 0, but fails to do anything else.
I put the right statements for the megunolink library, the command handler library, etc are all there. Somehow, it is ignoring the rest of the coding.
Serial.begin(9600);
SerialCommandHandler.AddCommand(F("SetBoolean"), Cmd_SetBoolean);
// SerialCommandHandler.AddVariable(F("setpoint"), setpoint); //!setpoint [alarmsetpoint.Value]\r\n
MyPlot.SetTitle("Airflow in Cubic Centimeters per minute (Ccm/min)");
MyPlot.SetXlabel("Time");
MyPlot.SetYlabel("Ccm/min");
// Set the plotting parameters. "flowrate" = series name, Plot::Blue = line colour
// 2 = line width, Plot::Square = marker style
MyPlot.SetSeriesProperties("flowrate", Plot::Blue, Plot::Solid, 2, Plot::NoMarker);
// Colours include
// Red, Green, Blue, Yellow, Black, Magenta, Cyan, White
// Markers include
// Square, Diamond, Triangle, Circle, Cross, Plus, Star, DownwardTriangle, NoMarker
// Line style
// Solid, Dashed, Dotted, DashDot, DashDotDot
lcd.begin(16,2);
//Activates and defines the LCD
lcd.clear();
}
void Cmd_SetBoolean(CommandParameter &Parameters)
{
Serial.print("Got new boolean:");
bool paramselect = (bool) Parameters.NextParameterAsInteger();
Serial.println(paramselect);
}
void loop()
{
digitalWrite (LEDPin,LOW);
//digitalRead(CFrun);
Airflowpanel.SetText("setpoint1", Ccmvar);
SerialCommandHandler.Process();
seconds = (float)millis()/1000;
//SerialCommandHandler.AddVariable(F("Setpoint3"), setpoint); // Setpoint3.Checked ? "3" : "6"
if (paramselect==1)
{
Ccmvar=3.00;
Airflowpanel.SetText("setpoint1", Ccmvar);
SerialCommandHandler.Process();
}
else
Ccmvar=6.00;
//while (CFrun==HIGH)
while (flowrate >= Ccmvar)
I put in a function:
void Cmd_SetBoolean(CommandParameter &Parameters)
{
Serial.print("Got new boolean:");
bool paramselect = (bool) Parameters.NextParameterAsInteger();
Serial.println(paramselect);
}
and I made a global variable:
bool paramselect = 1;
the sketch is supposed to send the interface a 3.00 or a 6.00 and generate a graph, neither of which is happening. Before I tried doing this, I had the chart working. now nothing. when i click on the radio button for 6, it sets the boolean variable to 0, but fails to do anything else.
I put the right statements for the megunolink library, the command handler library, etc are all there. Somehow, it is ignoring the rest of the coding.
Serial.begin(9600);
SerialCommandHandler.AddCommand(F("SetBoolean"), Cmd_SetBoolean);
// SerialCommandHandler.AddVariable(F("setpoint"), setpoint); //!setpoint [alarmsetpoint.Value]\r\n
MyPlot.SetTitle("Airflow in Cubic Centimeters per minute (Ccm/min)");
MyPlot.SetXlabel("Time");
MyPlot.SetYlabel("Ccm/min");
// Set the plotting parameters. "flowrate" = series name, Plot::Blue = line colour
// 2 = line width, Plot::Square = marker style
MyPlot.SetSeriesProperties("flowrate", Plot::Blue, Plot::Solid, 2, Plot::NoMarker);
// Colours include
// Red, Green, Blue, Yellow, Black, Magenta, Cyan, White
// Markers include
// Square, Diamond, Triangle, Circle, Cross, Plus, Star, DownwardTriangle, NoMarker
// Line style
// Solid, Dashed, Dotted, DashDot, DashDotDot
lcd.begin(16,2);
//Activates and defines the LCD
lcd.clear();
}
void Cmd_SetBoolean(CommandParameter &Parameters)
{
Serial.print("Got new boolean:");
bool paramselect = (bool) Parameters.NextParameterAsInteger();
Serial.println(paramselect);
}
void loop()
{
digitalWrite (LEDPin,LOW);
//digitalRead(CFrun);
Airflowpanel.SetText("setpoint1", Ccmvar);
SerialCommandHandler.Process();
seconds = (float)millis()/1000;
//SerialCommandHandler.AddVariable(F("Setpoint3"), setpoint); // Setpoint3.Checked ? "3" : "6"
if (paramselect==1)
{
Ccmvar=3.00;
Airflowpanel.SetText("setpoint1", Ccmvar);
SerialCommandHandler.Process();
}
else
Ccmvar=6.00;
//while (CFrun==HIGH)
while (flowrate >= Ccmvar)