I already have my code to work, I'm just trying to make it look nicer now. Just to give a really short summary on what my device does: Smart parking system that detects cars going in and out of a parking lot and displays how many vacant spots are available or not at the entrance. Right now the output looks like this:
Vacant Spots: 1
Vacant Spots: 1
Vacant Spots: 1
Vacant Spots: 1
Vacant Spots: 0
.
.
.
.
.
This is in the case of when a car is entering so it's decrementing by 1 and it increments when a car leaves since there's a added vacant spot available. What I'm trying to do is have the output look like this:
" Vacant Spots: 1
"
The only thing I want to change is the numerical value. I don't want a continuous stream of " Vacant Spots: 1 "s to show at the LCD display for the parking user to see. Is there a way to just clear the serial monitor after the loop ends without having it output a new value below it continuously? I've provided the code for the program. I have 3 xbees (1 coordinator and 2 routers). The two routers dont have code on them and are just sending data to the coordinator. The coordinator is where it receives the data. This is the code for the coordinator:
int readValue = 0;
void setup()
{
Serial.begin(9600);
}
int vslots = 1;
void loop()
{
if(Serial.available()>21)
{
if(Serial.read() == 0x7E)
{
for(int i=0;i<19;i++)
{
byte discard = Serial.read(); //Next 18 bytes, it's discarded
}
readValue = Serial.read();
bool flagTrue = false;
bool flagFalse = false;
if((readValue == 0) && flagTrue == false ) //EXIT
{
flagTrue = true;
flagFalse = false;
Serial.print("Vacant Spots: ");
Serial.println(vslots);
}
else if((readValue == 16 && flagFalse == false) && vslots >= 1)
//DECREMENT (CAR ENTERING)
{
flagTrue = false;
flagFalse = true;
vslots -= 1;
Serial.print("Vacant Spots: ");
Serial.println(vslots);
}
if((readValue == 18) && flagTrue == false )
{
flagTrue = true;
flagFalse = false;
Serial.print("Vacant Spots: ");
Serial.println(vslots);
}
else if((readValue == 19 && flagFalse == false) && vslots <= 10)
//INCREMENT (CAR EXITING)
{
flagTrue = false;
flagFalse = true;
vslots += 1;
Serial.print("Vacant Spots: ");
Serial.println(vslots);
}
}
}
}