check box

Support forum for MegunoLink
kanapaha
Posts: 1
Joined: Wed Jan 20, 2016 5:27 pm

Wed Jan 20, 2016 5:34 pm

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
alains
Posts: 17
Joined: Mon Oct 24, 2016 5:44 pm

Mon Oct 24, 2016 5:47 pm

Yes I have the same problem,would be nice to have the value of the check box equal to 0 or 1.
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Tue Oct 25, 2016 11:42 pm

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
griiker
Posts: 19
Joined: Wed Jun 27, 2018 12:27 am

Wed Jun 27, 2018 12:47 am

philr wrote: Tue Oct 25, 2016 11:42 pm 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
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
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Wed Jun 27, 2018 9:52 pm

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
griiker
Posts: 19
Joined: Wed Jun 27, 2018 12:27 am

Thu Jun 28, 2018 12:40 am

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
griiker
Posts: 19
Joined: Wed Jun 27, 2018 12:27 am

Thu Jun 28, 2018 1:00 am

Just one more thing

can I do something like this:

SerialCommandHandler.AddVariable(F("Setpoint3"), setpoint); // Setpoint3.Checked ? "3" : "6"

would that be okay?
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Thu Jun 28, 2018 3:19 am

I dont like the AddVariable approach. It should work though. Here is an example using 3 or 6.
RadioButton2.zip
(10.21 KiB) Downloaded 520 times
griiker
Posts: 19
Joined: Wed Jun 27, 2018 12:27 am

Thu Jun 28, 2018 4:14 am

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)
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Thu Jun 28, 2018 5:16 am

Can you please post your whole program. I will try to figure out whats going on when I get home.

Cheers
Phil
Post Reply