groundFungus:
I would suggest that you look at the serial input basics thread. You could modify the Example 3 - Receive with start- and end-markers. Use + for the start marker and K for the end marker. The markers are discarded. The if you want to convert from ASCII text to a float data type, use the atof() function.
Hey I want to compare values with a predefined value, in code below how can I do this?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
char myArray[12] = {"012345678AB"};
#include<string.h>
#include <LiquidCrystal.h>
const int rs = 31, en = 30, d4 = 28, d5 = 26, d6 = 24, d7 = 22;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int relay = 9;
int pot2 = A2;
int button = 7;
int button2 = 6;
int button3 = 5;
int button4 = 4;
int button5 = 3;
int button6 = 2;
int potvalue2 = 0;
int buttonvalue = 1;
int buttonvalue2 = 1;
int buttonvalue3 = 1;
int buttonvalue4 = 1;
int buttonvalue5 = 1;
int buttonvalue6 = 1;
char weight = 1;
char maxvalue = 1;
int maxvalue2 = 1;
char valid[50] = "false";
char valid2[50] = "false";
char valid3[50] = "false";
char valid4[50] = "false";
char valid5[50] = "false";
char valid6[50] = "false";
void setup()
{
pinMode(relay, OUTPUT);
pinMode(button, INPUT);
pinMode(button2, INPUT);
Serial.begin(9600);
mySerial.begin(9600);
digitalWrite(relay, 1);
lcd.begin(16, 2);
}
void loop()
{
Serial.println(analogRead(pot2));
delay(100);
{
while (mySerial.available() > 11)
{
myArray[0] = mySerial.read();
//find the first charater, +
if (myArray[0] == '+')
{
//read the remainding characters
for (byte i = 1; i < 12; i++)
{
myArray[i] = mySerial.read();
delay(1);
}
// Okay, myArray[1]thru myArray[7] has the data needed
//Test print the characters
for (byte i = 1; i < 8; i++)
{
Serial.print(myArray[i]);
}
Serial.println();
}
}
}
lcd.setCursor(0, 1);
lcd.print(myArray);
buttonvalue = digitalRead(button);
buttonvalue2 = digitalRead(button2);
buttonvalue3 = digitalRead(button3);
buttonvalue4 = digitalRead(button4);
buttonvalue5 = digitalRead(button5);
buttonvalue6 = digitalRead(button6);
if(!strcmp(valid,"true"))
{
buttonvalue=1;
}
if(!strcmp(valid2,"true"))
{
buttonvalue2=1;
}
if(!strcmp(valid3, "true"))
{
buttonvalue3=1;
}
if(!strcmp(valid4, "true"))
{
buttonvalue4=1;
}
if(!strcmp(valid5, "true"))
{
buttonvalue5=1;
}
if (!strcmp(valid6, "true"))
{
buttonvalue6=1;
}
//FIRST BUTTON
if(buttonvalue == 1)
{
digitalWrite(relay, 0);
strcpy(valid,"true");
maxvalue = 0.500;
lcd.setCursor(1,0);
lcd.print("WT INPUT:");
lcd.print(maxvalue);
if(!strcmp(valid,"true"))
{
weight = myArray;
}
if(myArray>maxvalue)
{
digitalWrite(relay, 1);
strcpy(valid,"false");
}
}
// SECOND SWITCH
else if(buttonvalue2 == 1)
{
digitalWrite(relay, 0);
strcpy(valid2,"true");
maxvalue = 1.000;
lcd.setCursor(1,0);
lcd.print("WT INPUT:");
lcd.print(maxvalue);
if(!strcmp(valid2,"true"))
{
myArray;
}
if (myArray>maxvalue)
{
digitalWrite(relay, 1);
strcpy(valid2,"false");
}
}
// 3rd Button
else if(buttonvalue3 == 1)
{
digitalWrite(relay, 0);
strcpy(valid3,"true");
maxvalue = 2.000;
lcd.setCursor(1,0);
lcd.print("WT INPUT:");
lcd.print(maxvalue);
if(!strcmp(valid3,"true"))
{
myArray;
}
if(myArray>maxvalue)
{
digitalWrite(relay, 1);
strcpy(valid3,"false");
}
}
// 4th Button
else if(buttonvalue4 == 1)
{
digitalWrite(relay, 0);
strcpy(valid4,"true");
maxvalue = 3.000;
lcd.setCursor(1,0);
lcd.print("WT INPUT:");
lcd.print(maxvalue);
if(!strcmp(valid4,"true"))
{
myArray;
}
if(myArray>maxvalue)
{
digitalWrite(relay, 1);
strcpy(valid4,"false");
}
}
// 5th Button
else if(buttonvalue5 == 1)
{
digitalWrite(relay, 0);
strcpy(valid5,"true");
maxvalue = 4.000;
lcd.setCursor(1,0);
lcd.print("WT INPUT:");
lcd.print(maxvalue);
if(!strcmp(valid5,"true"))
{
myArray;
}
if(myArray>maxvalue)
{
digitalWrite(relay, 1);
strcpy(valid5,"false");
}
}
// Manual Button-Set value by Potentiometer
else if(buttonvalue6 == 1)
{
digitalWrite(relay, 0);
strcpy(valid6,"true");
lcd.setCursor(1,0);
lcd.print("WT INPUT:");
lcd.print(maxvalue2);
if(!strcmp(valid6,"true"))
{
potvalue2 = analogRead(pot2);
myArray;
maxvalue2 = potvalue2;
}
if(myArray>maxvalue2)
{
digitalWrite(relay, 1);
strcpy(valid6,"false");
}
}
}