newbie needs help on serial

Hi, im new to the uno board, everything is looking good, except i cant clear the last data displayd befor i print the new value. How do i make the old one go away? I kno its a stupid question with a simple answer, but i cant find it and i have to turn it in tomorro. please help, and thank you in advance. here is the segment of code it applies to.
Grixx

x = y; // set x = y
if (digitalRead(entrancesensor)); // if the entrance sensor reads
else (y = y--); // then subtract 1 from y
if (x == y); // set a condition to compair x & y
else Serial.print(y); // and print y if they no longer match
delay(1000); // wait 1 second

Assumption as I do not have this info: According to your code you print to the serial monitor of the IDE. It is not possible to overwrite its output.
However if you use an VT100 compatible serial communication e.g. putty you could use VT100 codes to do so like in the code below

//
//    FILE: VT100.pde
//  AUTHOR: Rob Tillaart
//    DATE: 2010-11-10 
//
// PUPROSE: test VT100 codes
//

#define VT100_H

// http://ascii-table.com/ansi-escape-sequences-vt-100.php

#define OFF         "\033[0m"
#define BOLD        "\033[1m"
#define LOWINTENS   "\033[2m"
#define UNDERLINE   "\033[4m"
#define BLINK       "\033[5m"
#define REVERSE     "\033[7m"

#define GOTOXY( x,y) "\033[x;yH"   // Esc[Line;ColumnH

#define CLS          "\033[2J"     // Esc[2J Clear entire screen 


void setup()
{
  Serial.begin(9600);
}

void loop()
{

  Serial.print(BOLD);
  Serial.println("bold - Hello World");
  Serial.print(OFF);
  Serial.println("Goodbye");
  
  Serial.print(LOWINTENS);
  Serial.println("lowintense - Hello World");
  Serial.print(OFF);
  Serial.println("Goodbye");
  
  Serial.print(UNDERLINE);
  Serial.println("underline - Hello World");
  Serial.print(OFF);
  Serial.println("Goodbye");
  
  Serial.print(BLINK);
  Serial.println("blink - Hello World");
  Serial.print(OFF);
  Serial.println("Goodbye");
  
  Serial.print(REVERSE);
  Serial.println("reverse - Hello World");
  Serial.print(OFF);
  Serial.println("Goodbye");
  
  Serial.print(GOTOXY(3,3));
  Serial.println("gotoxy 3,3 - Hello World");
  Serial.print(OFF);
  Serial.println("Goodbye");  
  
  Serial.print(CLS);
  Serial.println("Hello World");
  Serial.print(OFF);
  Serial.println("Goodbye");
  while(1);
}

/*
Esc[20h 	Set new line mode 	LMN
Esc[?1h 	Set cursor key to application 	DECCKM
none 	Set ANSI (versus VT52) 	DECANM
Esc[?3h 	Set number of columns to 132 	DECCOLM
Esc[?4h 	Set smooth scrolling 	DECSCLM
Esc[?5h 	Set reverse video on screen 	DECSCNM
Esc[?6h 	Set origin to relative 	DECOM
Esc[?7h 	Set auto-wrap mode 	DECAWM
Esc[?8h 	Set auto-repeat mode 	DECARM
Esc[?9h 	Set interlacing mode 	DECINLM
 
Esc[20l 	Set line feed mode 	LMN
Esc[?1l 	Set cursor key to cursor 	DECCKM
Esc[?2l 	Set VT52 (versus ANSI) 	DECANM
Esc[?3l 	Set number of columns to 80 	DECCOLM
Esc[?4l 	Set jump scrolling 	DECSCLM
Esc[?5l 	Set normal video on screen 	DECSCNM
Esc[?6l 	Set origin to absolute 	DECOM
Esc[?7l 	Reset auto-wrap mode 	DECAWM
Esc[?8l 	Reset auto-repeat mode 	DECARM
Esc[?9l 	Reset interlacing mode 	DECINLM
 
Esc= 	Set alternate keypad mode 	DECKPAM
Esc> 	Set numeric keypad mode 	DECKPNM
 
Esc(A 	Set United Kingdom G0 character set 	setukg0
Esc)A 	Set United Kingdom G1 character set 	setukg1
Esc(B 	Set United States G0 character set 	setusg0
Esc)B 	Set United States G1 character set 	setusg1
Esc(0 	Set G0 special chars. & line set 	setspecg0
Esc)0 	Set G1 special chars. & line set 	setspecg1
Esc(1 	Set G0 alternate character ROM 	setaltg0
Esc)1 	Set G1 alternate character ROM 	setaltg1
Esc(2 	Set G0 alt char ROM and spec. graphics 	setaltspecg0
Esc)2 	Set G1 alt char ROM and spec. graphics 	setaltspecg1
 
EscN 	Set single shift 2 	SS2
EscO 	Set single shift 3 	SS3
 
Esc[m 	Turn off character attributes 	SGR0
Esc[0m 	Turn off character attributes 	SGR0
Esc[1m 	Turn bold mode on 	SGR1
Esc[2m 	Turn low intensity mode on 	SGR2
Esc[4m 	Turn underline mode on 	SGR4
Esc[5m 	Turn blinking mode on 	SGR5
Esc[7m 	Turn reverse video on 	SGR7
Esc[8m 	Turn invisible text mode on 	SGR8
 
Esc[Line;Liner 	Set top and bottom lines of a window 	DECSTBM
 
Esc[ValueA 	Move cursor up n lines 	CUU
Esc[ValueB 	Move cursor down n lines 	CUD
Esc[ValueC 	Move cursor right n lines 	CUF
Esc[ValueD 	Move cursor left n lines 	CUB
Esc[H 	Move cursor to upper left corner 	cursorhome
Esc[;H 	Move cursor to upper left corner 	cursorhome
Esc[Line;ColumnH 	Move cursor to screen location v,h 	CUP
Esc[f 	Move cursor to upper left corner 	hvhome
Esc[;f 	Move cursor to upper left corner 	hvhome
Esc[Line;Columnf 	Move cursor to screen location v,h 	CUP
EscD 	Move/scroll window up one line 	IND
EscM 	Move/scroll window down one line 	RI
EscE 	Move to next line 	NEL
Esc7 	Save cursor position and attributes 	DECSC
Esc8 	Restore cursor position and attributes 	DECSC
 
EscH 	Set a tab at the current column 	HTS
Esc[g 	Clear a tab at the current column 	TBC
Esc[0g 	Clear a tab at the current column 	TBC
Esc[3g 	Clear all tabs 	TBC
 
Esc#3 	Double-height letters, top half 	DECDHL
Esc#4 	Double-height letters, bottom half 	DECDHL
Esc#5 	Single width, single height letters 	DECSWL
Esc#6 	Double width, single height letters 	DECDWL
 
Esc[K 	Clear line from cursor right 	EL0
Esc[0K 	Clear line from cursor right 	EL0
Esc[1K 	Clear line from cursor left 	EL1
Esc[2K 	Clear entire line 	EL2
 
Esc[J 	Clear screen from cursor down 	ED0
Esc[0J 	Clear screen from cursor down 	ED0
Esc[1J 	Clear screen from cursor up 	ED1
Esc[2J 	Clear entire screen 	ED2
 
Esc5n 	Device status report 	DSR
Esc0n 	Response: terminal is OK 	DSR
Esc3n 	Response: terminal is not OK 	DSR
 
Esc6n 	Get cursor position 	DSR
EscLine;ColumnR 	Response: cursor is at v,h 	CPR
 
Esc[c 	Identify what terminal type 	DA
Esc[0c 	Identify what terminal type (another) 	DA
Esc[?1;Value0c 	Response: terminal type code n 	DA
 
Escc 	Reset terminal to initial state 	RIS
 
Esc#8 	Screen alignment display 	DECALN
Esc[2;1y 	Confidence power up test 	DECTST
Esc[2;2y 	Confidence loopback test 	DECTST
Esc[2;9y 	Repeat power up test 	DECTST
Esc[2;10y 	Repeat loopback test 	DECTST
 
Esc[0q 	Turn off all four leds 	DECLL0
Esc[1q 	Turn on LED #1 	DECLL1
Esc[2q 	Turn on LED #2 	DECLL2
Esc[3q 	Turn on LED #3 	DECLL3
Esc[4q 	Turn on LED #4 	DECLL4
 
 
Codes for use in VT52 compatibility mode
Esc< 	Enter/exit ANSI mode (VT52) 	setansi
 
Esc= 	Enter alternate keypad mode 	altkeypad
Esc> 	Exit alternate keypad mode 	numkeypad
 
EscF 	Use special graphics character set 	setgr
EscG 	Use normal US/UK character set 	resetgr
 
EscA 	Move cursor up one line 	cursorup
EscB 	Move cursor down one line 	cursordn
EscC 	Move cursor right one char 	cursorrt
EscD 	Move cursor left one char 	cursorlf
EscH 	Move cursor to upper left corner 	cursorhome
EscLineColumn 	Move cursor to v,h location 	cursorpos(v,h)
EscI 	Generate a reverse line-feed 	revindex
 
EscK 	Erase to end of current line 	cleareol
EscJ 	Erase to end of screen 	cleareos
 
EscZ 	Identify what the terminal is 	ident
Esc/Z 	Correct response to ident 	identresp

 

 
VT100 Special Key Codes

These are sent from the terminal back to the computer when the particular key is pressed. 
Note that the numeric keypad keys send different codes in numeric mode than in alternate mode. 
See escape codes above to change keypad mode.

 

Function Keys:
EscOP	PF1
EscOQ	PF2
EscOR	PF3
EscOS	PF4

 

Arrow Keys:
  	Reset 	Set
up 	EscA	EscOA
down 	EscB	EscOB
right 	EscC	EscOC
left 	EscD	EscOD

 

Numeric Keypad Keys:
EscOp	0
EscOq	1
EscOr	2
EscOs	3
EscOt	4
EscOu	5
EscOv	6
EscOw	7
EscOx	8
EscOy	9
EscOm	-(minus)
EscOl	,(comma)
EscOn	.(period)
EscOM	^M

 

Printing:
Esc[i 	Print Screen 	Print the current screen
Esc[1i	Print Line 	Print the current line
Esc[4i	Stop Print Log 	Disable log
Esc[5i	Start Print Log	Start log; all received text is echoed to a printer

*/

The if statement rarely ends in a semi-colon, unless it is in error.

@Paul,
I had to think twice too , it is a bit obfuscated construction :

if (digitalRead(entrancesensor) != LOW ) ; // do nothing
else y = y-1;

It would be more readable when written

if (digitalRead(entrancesensor) == HIGH) y = y -1; // or y--;

@robtillaart
I figured the same thing, but I wanted OP to explain that, so that we could explain the ! operator and how to reverse the logic so the else clause is not required.

Or, in the few cases where it is difficult to reverse the logic, the addition of a comment that says "Yes, I know this does nothing" should be added where the nothing occurs.

I don't understand the need for the

y = y--;

assignment, either. It tells me that OP doesn't understand what y-- is doing.

I was trying to subtract 1 from the value of y and return the new value to y. Y being the number of available spaces. This is the entire code I turnd in, can I get an honest opinion. Ok, I figured out that serial out is raw data (duh, i said it was probably something stupid) and should have set up a quick and dirty web server, but resources run thin when your lab partners are tweetle dee and tweetle dum.

/*
Code written by Michael T Waugh
Jan - Feb 2011
Capstone Project
Professor Smellie
ITT Tech, Owings Mills, MD
The Isaac Asimov Intelligent Parking Facility
Arduino Uno board using Atmega328 chip
Sharp GP2YOD805Z0F Digital Distance Sensors (DDS) determine if parking space is in use
LED's indicate what parking spaces are in use
Sharp GP2YOD810Z0F DDS entrance & exit sensors account for cars in the garage but not yet parked
Serial out to display, digital pins 1 & 0 must be left open
Color indicates wire used, change at your discretion

LED anode to digital pin 5 parking space 1 Yellow
LED anode to digital pin 6 parking space 2 Blue
LED anode to digital pin 7 parking space 3 Purple
all LED cathodes to common ground Black
Sharp GP2YOD805Z0F DDS out pin to digital 8 parking space 1 Yellow
Sharp GP2YOD805Z0F DDS out pin to digital 9 parking space 2 Blue
Sharp GP2YOD805Z0F DDS out pin to digital 10 parking space 3 Purple
Sharp GP2YOD810Z0F DDS out pin to digital 13 entrance sensor Green
Sharp GP2YOD810Z0F DDS out pin to digital 12 exit sensor Yellow
all Sharp DDS Vin to +5V Red
all Sharp DDS gnd to common ground Black
*/
int ledspace1 = 5; // LED for parking space 1 set to digital pin 5
int ledspace2 = 6; // LED for parking space 2 set to digital pin 6
int ledspace3 = 7; // LED for parking space 3 set to digital pin 7
int sensorspace1 = 8; // sensor on parking space 1 set to digital pin 8
int sensorspace2 = 9; // sensor on parking space 2 set to digital pin 9
int sensorspace3 = 10; // sensor on parking space 3 set to digital pin 10
int valspace1 = 0; // variable to store the read value for parking space 1
int valspace2 = 0; // variable to store the read value for parking space 2
int valspace3 = 0; // variable to store the read value for parking space 3

int entrancesensor = 13; // sensor on entrance set to digital pin 13
int exitsensor = 12; // sensor on exit set to digital pin 12
int x = 3; // constant to store total number of spaces
int y = 3; // variable to store actual spaces

void setup()
{
Serial.begin(9600); // open the serial port at 9600 bps
pinMode(ledspace1, OUTPUT); // sets the digital pin 5 as output
pinMode(ledspace2, OUTPUT); // sets the digital pin 6 as output
pinMode(ledspace3, OUTPUT); // sets the digital pin 7 as output
pinMode(sensorspace1, INPUT); // sets the digital pin 8 as input
pinMode(sensorspace2, INPUT); // sets the digital pin 9 as input
pinMode(sensorspace3, INPUT); // sets the digital pin 10 as input
pinMode(exitsensor, INPUT); // sets the digital pin 12 as input
pinMode(entrancesensor, INPUT); // sets the digital pin 13 as input
Serial.println("Isaac Asimov Intelligent Parking Facility" );// displays Isaac etc...
Serial.println("Spaces available:"); // prints the available spaces
Serial.print(y);
}
void loop()
{

if (digitalRead(entrancesensor)); // if the entrance sensor reads
else (y = y--); Serial.print(y); // then subtract 1 from the total spaces & print
delay(1000); // wait 1 second

valspace1 = digitalRead(sensorspace1); // read parking sensor 1
digitalWrite(ledspace1, valspace1); // sets the LED to parking sensor 1 value
valspace2 = digitalRead(sensorspace2); // read parking sensor 2
digitalWrite(ledspace2, valspace2); // sets the LED to parking sensor 2 value
valspace3 = digitalRead(sensorspace3); // read parking sensor 3
digitalWrite(ledspace3, valspace3); // sets the LED to parking sensor 3 value

if (digitalRead(exitsensor)); // if the exit sensor reads
else (y = y++); Serial.print(y); // then add 1 to the total spaces & print
delay(1000); // wait 1 second
}

if (digitalRead(entrancesensor));                         // if the entrance sensor reads

The digitalRead function returns a value. This statement is equivalent to this:

int val = digitalRead();
if(val)
{
}

If val == what? Do nothing? Are you sure that is what you want to do? If so, why not explicitly state that?

      else (y = y--); Serial.print(y);                             // then subtract 1 from the total spaces & print

When there is a difference between the comments and the code, the code is right. This comment is wrong. The statement is unnecessarily complex.

y--;

is equivalent to y = y - 1; Your statement, then, is equivalent to y = y = y - 1;

Since there are no curly braces (beginners should ALWAYS use curly braces after EVERY if statement, else statement, for statement, and while statement) the Serial.print() statement will be executed regardless of whether the if statement evaluated to true or false.

Putting more than one statement on a line is a sure way of introducing bugs (unintended behavior) into a program.

but resources run thin when your lab partners are tweetle dee and tweetle dum.

So far, I'm not too impressed with tweedle dee and tweedle dum's lab partner.

so you are saying that:
if (digitalRead(entrancesensor)); // if the entrance sensor reads
else (y = y--); Serial.print(y); // then subtract 1 from the total spaces & print
delay(1000); // wait 1 second

should read:
int val = digitalRead(entrancesensor); // set val when sensor reads
{
if(val) y--; // if val reads high, sub 1 from y and return that value to y
Serial.print(y) // send y down the serial

the Serial.print() statement will be executed regardless of whether the if statement evaluated to true or false.
i should note that this Serial.print() did print only when the sensor read an object. In fact, the whole project worked as advertised, sub 1 and print when the entrance read, add one and print when the exit sensor read, worked perfect with the exception of using serial out as a final display, but i finaly figured that out(that was my original question). any advice on conecting to web servers? ... another time maybee

So far, I'm not too impressed with tweedle dee and tweedle dum's lab partner.
tweele dee couldn't give me a powerpoint with one background image, animation, or even color. tweedle dum couldnt give me a full one page write up on any single componet we used. now i may may be a newbie, at least i try

btw, thanks for all the help

should read:
int val = digitalRead(entrancesensor);

No!
No semicolon

then

int val = digitalRead(entrancesensor); // set val when sensor reads
{
if(val) y-- // if val reads high, sub 1 from y and return that value to y
Serial.print(y) // send y down the serial
}

oops i ment

int val = digitalRead(entrancesensor) // set val when sensor reads
{
if(val) y--; // if val reads high, sub 1 from y and return that value to y
Serial.print(y) // send y down the serial
}

color me stupid

int val = digitalRead(entrancesensor);
{
  if(val == HIGH)
    y--;
  Serial.print(y);
}

Put semicolons where they are needed, but only where they are needed. Of course, this supposes that you know the difference.

Comments should describe what you are going to do, not what you have done. Anyone can look at the statement Serial.print(y); and see that is is going to send the value in y to the serial port. A comment to this effect tells the reader that you think he/she is a moron.

Comments prior to the block of code that say something like
// Read the entrance sensor, increment the number
// of entrances if high, and report that new value
would describe what you are doing, without offending the intellect of the reader.

In an if test, unless the variable is either a pointer or a boolean, there should be an explicit value to compare to. Yes, it will work the way you have it. But, if you change the hardware to remove the external resistor, and use the internal pullup resistor, the comparison you had will no longer work. Changing the explicit value I have from HIGH to LOW will continue to work.

I see, having an explicit value to compare in an if statement will guarantee the desired result even if the hardware changed.

Sorry if my //comments seem insulting, we're told to write them as if someone who knows less than us is trying to figure it out. They want them on every line, I think to make sure we know what every line in the code is doing. I find it a bit excessive, but helpful when I try to walk through the logic. But that's just me, and what do I know, I'm a newbi.

Here is how I would debug your code. My comments are meant for you to understand what I changed and why.

int car_count=0;                                                   //This is a better variable name than y. I can instantly see the purpose of this variable
void loop()
{

  if (digitalRead(entrancesensor)==LOW)                // While in most languages an if statement will fire if the value is not 0, best practice is to always compare to something.
  {                                                                        // Note: no ; in the line above. {...code...} replaces a ;
      car_count++;                                                 // Moved this from the bottom, no need for 2 of the same if statement when nothing is changing the variables from here and there
      Serial.println(car_count);                                  // Changed to println so it will print 1 number on a line, making it easier to read than 123456789101112
  }
  if(digitalRead(exitsensor)==LOW)                        // Moved this to under the other if statement since it makes it easier to see what exactly you're doing
  {                                                                        //  which is add 1 to car_count if someone is entering, subtract 1 if someone is leaving
      car_count--;
      Serial.println(car_count);
  }

/* omitted because I see no problems with LED stuff */

  delay(1000);                                                       // This being outside the if statement will make it always wait 1 second even if the sensor is reading 0 or both sensors are reading 1
                                                                            // Before it would delay 0, 1, or 2 seconds. Also, having this at the bottom of loop will instantly turn on the LEDs instead of waiting.

Now then, an issue I see with what you are trying to do is that if a car takes more than 1 second to pass over/through the entrance and exit sensors, you are going to be counting more cars than there really are (or fewer if it is the exit sensor). What I would do is change the delay to 100 ms, and have 1 boolean variables. 1 for the previous state of the entrance and 1 for previous state of the exit. Then change your code to more like this:

if(digitalRead(entrancesensor)==LOW && prev_entrance == HIGH)
{ /*do stuff*/ }
if(digitalRead(exitsensor)==LOW && prev_exit == HIGH)
{ /*do stuff*/ }
prev_entrance=digitalRead(entrancesensor);
prev_exit=digitalRead(exitsensor);

This looks for a change in state (the sensor going from HIGH to LOW) instead of only looking at the current state.

thank you all for your help, you've given me alot of info
G