Hey guys, so I am creating a code, but I am stuck as to how I can actually input values into the serial monitor. I want different values such as AgeAdult, AgeTeen, and AgeKid to show different settings within my device, can you guys help me with this(P.S., I have been working on this for a long time and if you need any reference, please go to my profile and see my other questions)
#include <CountUpDownTimer.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int FSRPin = A0; // force sensitive resistor
const int ColorPin = 9; // ColorStat Sensor
const int LedPin = 13; // OUTPUTPIN
CountUpDownTimer T(DOWN);
LiquidCrystal_I2C lcd(0x27, 16, 2);
// time values
int initial = 1;
int timeon = 0;
int mins = 0;
int secs = 10;
int start_time = 0;
int end_time = 0;
int elapased_time = 0;
// sensor values
int colorValue = 0;
int FSRValue = 0;
float temp = 0.0;
int sensorValue = 0;
// control values
int flag = 1;
int command = 0;
#define ONTIME 10
//Linear Actuator
int Threshold = 0; // Add more threshold integers based on different cases?
const int A1B = 7; // In1
const int A1A = 8; // In2
int RESISTOR_READING = 0;
//Serial Monitor Variables
String TheAge;
int AgeAdult;
int AgeTeen;
int AgeKid;
int Retract;
String mesg="Enter Age.";
void setup()
{
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Started...");
Serial.begin(9600);
Serial.println("Initializing...");
Serial.println("Started...");
pinMode(FSRPin, INPUT);
pinMode(ColorPin, INPUT);
pinMode(LedPin, OUTPUT);
digitalWrite(LedPin, LOW);
T.SetTimer(0, 0, 0, 10);
T.StartTimer();
command = 0;
pinMode(A1A, OUTPUT);
pinMode(A1B, OUTPUT);
}
int smooth()
{
return analogRead(FSRPin);
}
void loop()
{
FSRValue = smooth();
colorValue = digitalRead(ColorPin);
RESISTOR_READING = digitalRead(FSRValue);
Serial.println(mesg);
while (Serial.available() ==0) {
Serial.println("I am waiting...");
delay(10000);
}
TheAge=Serial.readString();
if(TheAge = AgeAdult) {
Serial.println("Age: Adult");
analogWrite(A1B, 0);
analogWrite(A1A, 225);
takeMeasurement("Adult");
delay(1000);
lcd.print("Starting");
delay(250);
}
TheAge=Serial.readString();
if(TheAge = AgeTeen) {
Serial.println("Age: Teen");
takeMeasurement("teen");
delay(1000);
lcd.print("Starting");
analogWrite(A1B, 0);
analogWrite(A1A, 225);
delay(250);
}
TheAge=Serial.readString();
if(TheAge = AgeKid) {
Serial.println("Age: Kid");
takeMeasurement("Kid");
delay(1000);
lcd.print("Starting");
analogWrite(A1B, 0);
analogWrite(A1A, 225);
delay(250);
}
TheAge=Serial.readString();
if (TheAge = Retract); {
analogWrite(A1B, 201);
analogWrite(A1A, 0);
delay(250);
}
//if(TheAge=0)
{
lcd.setCursor(0, 0);
lcd.print("Need More Pressure");
Serial.print(" -> Need More Pressure");
analogWrite(A1B, 201);
analogWrite(A1A, 225);
sensorValue = 0;
Threshold = 0;
}
}
void takeMeasurement(String age)
{
if (age == "Kid")
{
Threshold = 300;
lcd.setCursor(0, 0);
lcd.print("Kids 6-12 Years");
Serial.print(" -> Kids 6-12 Years");
sensorValue = 1;
if (RESISTOR_READING >= 300)
{
analogWrite(A1B, 201);
analogWrite(A1A, 225);
}
}
else if (age == "Teen")
{
Threshold = 400;
lcd.setCursor(0, 0);
lcd.print("Teen 13-19 Years");
Serial.print("-> Teens 13-19 Years");
sensorValue = 1;
if (RESISTOR_READING >= 400)
{
analogWrite(A1B, 201);
analogWrite(A1A, 225);
}
}
else if (age == "Adult")
{
Threshold = 600;
lcd.setCursor(0, 0);
lcd.print("Adult");
Serial.print("-> Adult");
sensorValue = 1;
}
if (RESISTOR_READING >= 600)
{
analogWrite(A1B, 201);
analogWrite(A1A, 225);
delay(1000);
}
if (sensorValue == 1)
{
timeon = 1;
}
else
{
timeon = 0;
}
if (timeon == 1)
{
// T.Timer();
digitalWrite(LedPin, HIGH);
if (T.TimeHasChanged())
{
Serial.print(":");
Serial.print(T.ShowSeconds());
lcd.setCursor(0, 1);
lcd.print(T.ShowSeconds());
}
if (T.ShowSeconds() == 0)
{
T.ResetTimer();
lcd.clear();
lcd.print("Release Pressure");
Serial.println("Release the Pressure");
digitalWrite(LedPin, LOW);
command = 2;
// timeon=0;
// sensorValue=0;
// break;
}
}
Serial.println("");
// case 2:
//delay(10);
if (FSRValue == 0 && colorValue == 0)
{
// T.ResetTimer();
// T.Timer(); // run the timer
Serial.print(" ");
Serial.print(millis());
Serial.println("");
T.SetTimer(0, 0, 0, 5);
lcd.clear();
lcd.print("Start Time");
command = 3;
start_time = millis();
// break;
}
Serial.println("");
// case 3:
if (FSRValue == 0 && colorValue == 1) // (flag==1)
{
// Serial.print(" ");
// Serial.print(millis());
// Serial.println("");
//Serial.println("State :3");
command = 4;
T.SetTimer(0, 0, 0, 5);
end_time = millis();
lcd.clear();
lcd.print("End Time");
flag = 0;
elapased_time = (end_time - start_time) / 1000;
Serial.print("Elapased Time : ");
Serial.println(elapased_time);
delay(1000);
lcd.clear();
lcd.print("elapased_time : "); // Added this print statement
lcd.print(elapased_time);
// break;
}
else
{
Serial.print("");
}
Serial.println("");
// case 4:
if (flag == 0)
{
T.Timer(); // run the timer
if (T.TimeHasChanged()) // this prevents the time from being constantly shown.
{
Serial.print(":");
Serial.print(T.ShowSeconds());
// lcd.clear();
// lcd.print(T.ShowSeconds());
}
if (T.ShowSeconds() == 0)
{
T.ResetTimer();
command = 0;
T.SetTimer(0, 0, 0, 10);
flag = 1;
// break;
}
}
Serial.println("");
// }
delay(1000);
}
thank you