Just a little help please
Posted: Thu Jan 10, 2019 4:53 am
Hello anyone out there?
So I need a little help. I have written this program that will require a floating value to be sent from Arduino to Meguno.
User inputs an one decimal number (23.5),into a number box. Then click a button to broadcast on the serial bus the number. Arduino receives that number (loco) and drives a motor one direct or the other depending on the rigs current location(DataValue). OK, here is where trouble comes in handy. The rig is connected to a pot(A0) that ready analog value, maps the range, and should report back to meguno its current location. An text box or number box should display an one decimal number.
Link to files https://drive.google.com/open?id=1Ya_Qp ... cztrtqEhGh
Question, how do I get my arduino to conform to those behavior?
Also, changing colour commands does not work. Any idea?
Please disregard the jibber jabber. Alot of brain cells have been fried getting this far.
#include "MegunoLink.h"
#include "CommandHandler.h"
float Loco;
float DataValue;
int BlinkDelayTime = 500;
//serial interface button
InterfacePanel MyPanel;
CommandHandler<> SerialCommandHandler; //serial comms
//void Cmd_GetLoco2(CommandParameter &Parameters)
// {
//Serial.print("GetLoco2");
//Loco=Parameters.NextParameterAsInteger();// needed for comms
// }
void Cmd_SetLoco(CommandParameter &Parameters)
{
Loco=Parameters.NextParameterAsInteger(Loco);// needed for comms
}
const int pot = A2;// open a ver 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.AddVariable(F("SetLoco"), Loco);
}
void loop()
{
DataValue = analogRead(pot);
DataValue = map(DataValue, 0, 1023, 0, 50);
Serial.print("Loco "); Serial.println(Loco); // this will show me values. for test only
Serial.print("DataValue "); Serial.println(DataValue);// this will show me values. for test only
//Progress bars
MyPanel.SetProgress(F("IP9"), DataValue);
// Set control value
MyPanel.SetNumber(F("IPNumericUpDown1"), DataValue,2);
if (Loco == 0)
{MyPanel.SetText(F("Set"), "Stopped");}
if (Loco > 0)
{MyPanel.SetText(F("Set"), "Running");}
//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("ToP9"), "To Pin");
delay (BlinkDelayTime);
MyPanel.SetText(F("ToP9"), "<--- ");
delay (BlinkDelayTime);
//MyPanel.SetForeColor(F("Status"), "Green");
}
if (Loco < DataValue)
{
digitalWrite(Adv, LOW);
digitalWrite(Stay, LOW);
digitalWrite(Ret, HIGH);
MyPanel.SetText(F("FromP9"), "From Pin");
delay (BlinkDelayTime);
MyPanel.SetText(F("FromP9"), "---> ");
delay (BlinkDelayTime);
//MyPanel.SetForeColor(F("Status"), "Blue");
}
if (Loco == DataValue)
{
digitalWrite(Adv, LOW);
digitalWrite(Stay, HIGH);
digitalWrite(Ret, LOW);
MyPanel.SetText(F("HoldP9"), "HOLD");
delay (BlinkDelayTime);
MyPanel.SetText(F("HoldP9"), "---- ");
delay (BlinkDelayTime);
//MyPanel.SetForeColor(F("Status"), "Red");
}
// command handler instrucion
SerialCommandHandler.Process();
So I need a little help. I have written this program that will require a floating value to be sent from Arduino to Meguno.
User inputs an one decimal number (23.5),into a number box. Then click a button to broadcast on the serial bus the number. Arduino receives that number (loco) and drives a motor one direct or the other depending on the rigs current location(DataValue). OK, here is where trouble comes in handy. The rig is connected to a pot(A0) that ready analog value, maps the range, and should report back to meguno its current location. An text box or number box should display an one decimal number.
Link to files https://drive.google.com/open?id=1Ya_Qp ... cztrtqEhGh
Question, how do I get my arduino to conform to those behavior?
Also, changing colour commands does not work. Any idea?
Please disregard the jibber jabber. Alot of brain cells have been fried getting this far.
#include "MegunoLink.h"
#include "CommandHandler.h"
float Loco;
float DataValue;
int BlinkDelayTime = 500;
//serial interface button
InterfacePanel MyPanel;
CommandHandler<> SerialCommandHandler; //serial comms
//void Cmd_GetLoco2(CommandParameter &Parameters)
// {
//Serial.print("GetLoco2");
//Loco=Parameters.NextParameterAsInteger();// needed for comms
// }
void Cmd_SetLoco(CommandParameter &Parameters)
{
Loco=Parameters.NextParameterAsInteger(Loco);// needed for comms
}
const int pot = A2;// open a ver 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.AddVariable(F("SetLoco"), Loco);
}
void loop()
{
DataValue = analogRead(pot);
DataValue = map(DataValue, 0, 1023, 0, 50);
Serial.print("Loco "); Serial.println(Loco); // this will show me values. for test only
Serial.print("DataValue "); Serial.println(DataValue);// this will show me values. for test only
//Progress bars
MyPanel.SetProgress(F("IP9"), DataValue);
// Set control value
MyPanel.SetNumber(F("IPNumericUpDown1"), DataValue,2);
if (Loco == 0)
{MyPanel.SetText(F("Set"), "Stopped");}
if (Loco > 0)
{MyPanel.SetText(F("Set"), "Running");}
//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("ToP9"), "To Pin");
delay (BlinkDelayTime);
MyPanel.SetText(F("ToP9"), "<--- ");
delay (BlinkDelayTime);
//MyPanel.SetForeColor(F("Status"), "Green");
}
if (Loco < DataValue)
{
digitalWrite(Adv, LOW);
digitalWrite(Stay, LOW);
digitalWrite(Ret, HIGH);
MyPanel.SetText(F("FromP9"), "From Pin");
delay (BlinkDelayTime);
MyPanel.SetText(F("FromP9"), "---> ");
delay (BlinkDelayTime);
//MyPanel.SetForeColor(F("Status"), "Blue");
}
if (Loco == DataValue)
{
digitalWrite(Adv, LOW);
digitalWrite(Stay, HIGH);
digitalWrite(Ret, LOW);
MyPanel.SetText(F("HoldP9"), "HOLD");
delay (BlinkDelayTime);
MyPanel.SetText(F("HoldP9"), "---- ");
delay (BlinkDelayTime);
//MyPanel.SetForeColor(F("Status"), "Red");
}
// command handler instrucion
SerialCommandHandler.Process();