Changing colors

Support forum for MegunoLink
Post Reply
supershepp
Posts: 10
Joined: Mon Jan 07, 2019 12:12 am

Mon Jan 07, 2019 7:35 pm

So i'm having a bit of an issue trying to figure out how to change the forecolor and backcolors of my dynamic label or progression bar. Anyone out their can give me a hand?

my code is to read a pot and display the pot position. Then set a location for the motor to turn the pot to that location. I would like to display different colors to show what direction the motor is spinning and when it stops on the corresponding set location.

Here is my code. When I put the code from the example into my loop in an IF statement. My Arduion errors out with an " no matching function for call".

#include "MegunoLink.h"
#include "CommandHandler.h"

//serial interface button
int Loco = 0;
CommandHandler<> SerialCommandHandler; //serial comms

void Cmd_GetLoco(CommandParameter &Parameters)
{
Parameters.GetSource().print(F("Value of set location = "));// print text on serial bus
Parameters.GetSource().println(Loco);
}

void Cmd_SetLoco(CommandParameter &Parameters)
{
Loco=Parameters.NextParameterAsInteger(Loco);// needed for comms
}

InterfacePanel MyPanel;// interface panel
const int pot = A2;// open a var box for location bar
const int Adv = 2;// open a var box for advancing the motor
const int Stay = 3;// open a var box to stop movement
const int Ret = 4;// open a var box for retracting the motor

void setup()
{
Serial.begin(9600);
pinMode(Adv,OUTPUT);
pinMode(Stay,OUTPUT);
pinMode(Ret,OUTPUT);

SerialCommandHandler.AddCommand(F("SetLoco"), Cmd_SetLoco);// commands to read interface commands
SerialCommandHandler.AddCommand(F("GetLoco"), Cmd_GetLoco);//commands to read interface commands
}
void loop()
{
//Progress bars
float DataValue = analogRead(pot);
Serial.println(Loco);
delay(250);
MyPanel.SetProgress(F("IPProgressBar1"), DataValue);
delay(250);

if (Loco == 0)
{MyPanel.SetText(F("Set"), "NO location Set.");}
if (Loco > 0)
{MyPanel.SetText(F("Set"), "Ready for Action.");}
//MyPanel.SetForeColor(F("Status"), "Red");
//MyPanel.SetBackColor(F("Status"), "Blue");

if (Loco > DataValue)
{
digitalWrite(Adv, HIGH);
digitalWrite(Stay, LOW);
digitalWrite(Ret, LOW);
MyPanel.SetText(F("Status"), "To Pin");
//MyPanel.SetForeColor(F("Status"), "Green");
}
if (Loco < DataValue)
{
digitalWrite(Adv, LOW);
digitalWrite(Stay, LOW);
digitalWrite(Ret, HIGH);
MyPanel.SetText(F("Status"), "From Pin");
//MyPanel.SetForeColor(F("Status"), "Blue");
}
if (Loco == DataValue)
{
digitalWrite(Adv, LOW);
digitalWrite(Stay, HIGH);
digitalWrite(Ret, LOW);
MyPanel.SetText(F("Status"), "Hold");
//MyPanel.SetForeColor(F("Status"), "Red");
}
// command handler instruction
SerialCommandHandler.Process();
}
philr
Posts: 238
Joined: Mon May 26, 2014 10:58 am

Wed Jan 09, 2019 8:17 am

Hi, I just tested the colour properties here and it seemed to work. Can you capture the serial messages sent from your device in the monitor? Do they look like this:
{UI|SET|MyLabel.ForeColor=blue}
{UI|SET|MyLabel.ForeColor=red}
{UI|SET|MyLabel.ForeColor=green}
{UI|SET|MyLabel.ForeColor=black}
{UI|SET|MyLabel.BackColor=blue}
{UI|SET|MyLabel.BackColor=red}
{UI|SET|MyLabel.BackColor=green}
{UI|SET|MyLabel.BackColor=white}

Make sure that the name of your label is correct. In my case its "MyLabel".

Cheers
Phil
supershepp
Posts: 10
Joined: Mon Jan 07, 2019 12:12 am

Wed Jan 09, 2019 5:49 pm

Thanks for your input sir,
Their is no command on the Serial bus. The code is crashing in the compiler.
I notice when i type the words "SetForeColor" , this text does not change colors (orange) as it does when i type "SetNumber" or "Serial. print"
it's as if Ardurino ide does not recognize these commands.
philr
Posts: 238
Joined: Mon May 26, 2014 10:58 am

Thu Jan 10, 2019 5:48 am

Hi, just tried it out here and found the issue. You need to change to
MyPanel.SetForeColor(F("Status"), F("Red"));
or
MyPanel.SetForeColor("Status", "Red");

Rather than
MyPanel.SetForeColor(F("Status"), "Red");

Cheers
Phil
supershepp
Posts: 10
Joined: Mon Jan 07, 2019 12:12 am

Mon Jan 14, 2019 10:22 pm

can the forecolor and backcolor be changed on the progression bar? i would like it to change colors at a preset point during the progression. The example color changing does not work. with or without the F() code.
philr
Posts: 238
Joined: Mon May 26, 2014 10:58 am

Sun Jan 20, 2019 8:02 am

Hi, no I don't think those properties do anything for progress bars. You can try change them in the designer and nothing changes so I don't think its possible.

Cheers
Phil
Post Reply