That helped! Thank you!
One last problem and then I think I should be good! I've been working your help out separate code than the one I want to use it on, just to eliminate potential errors. Essentially something works on the scratch sheet of code, if you will, but doesn't on my main code. Any thoughts?
Scratch code
// parse serial data input 125.75, 61.73,243.69
char myData[30] = { 0 }, s1[10], s2[10], s3[10];
float a = 0;
float b = 0;
float c = 4;
int count=0;
void setup() {
Serial.begin(115200);
Serial.print("Enter three variables seprated by spaces");
Serial.println();
}
void loop() {
byte n = Serial.available();
if (n != 0) {
byte m = Serial.readBytesUntil('\n', myData, 30);
myData[m] = '\0'; //null-byte
float y1, y2, y3;
if (sscanf(myData, "%[^','],%[^','],%s", s1, s2, s3) == 3) {
y1 = atof(s1);
y2 = atof(s2);
y3 = atof(s3);
Serial.println("parsed three strings ok");
Serial.print("float y1 = ");
Serial.println(y1, 2);
Serial.print("float y2 = ");
Serial.println(y2, 2);
Serial.print("float y3 = ");
Serial.println(y3, 2);
a = y1/y2;
b = y3;
} else Serial.println("error in input!");
}
if(a>0 && count<1)
{
if(b <= a) //This works just fine here***
{
Serial.print("Division of y2 by y1: ");
Serial.println(a);
Serial.print("Answer of 4 multiplied by y3: ");
Serial.println(b);
count++; //Just so it prints out once
}
}
}
Main code
void loop()
{
// Get the weight on the scale.
float weight;
weight = scale.get_units();
float percentage;
byte n = Serial.available();
if (n != 0) {
byte m = Serial.readBytesUntil('\n', myData, 30);
myData[m] = '\0'; //null-byte
float input, lower, upper;
if (sscanf(myData, "%[^','],%[^','],%s", s1, s2, s3) == 3) {
input = atof(s1);
lower = atof(s2);
upper = atof(s3);
Serial.println("parsed three strings ok");
Serial.print("float input = ");
Serial.println(input, 2);
Serial.print("float lower = ");
Serial.println(lower, 2);
Serial.print("float upper = ");
Serial.println(upper, 2);
// Calculate the percentage and trucate at the integer value
percentage = (weight / input * 100);
}
}
// Test the weight being applied to the scale.
if (weight > 15){
if (lower <= percentage && percentage <= upper) { //But doesn't here here***
//Rest of the code follows
With the error being
error: 'lower' was not declared in this scope
and
error: 'upper' was not declared in this scope