Hi..i have a question, maybe a noob one for ppl who know. I have maked a counter each time when i press the button the counter increments with 1 and display on serial something like:
nr = 1, nr = 2, nr = 3 ...etc. What i wanna know and i have tryed over 4 days is how i diplay only once the value on a single line and each time when i count, ""to somehow overwrite"" the existing value and displayng it like: ""nr = 1"" then on the same line 1 is replaced with 2..then with 3 and so on every time i count. More simple, then same line remains unchanged and only the value get overrited (upgraded).
HERE IS THE CODE:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 10; // the pin that the LED is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup()
{
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState)
{
if (buttonState == HIGH)
{
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
Serial.write('\n');
Serial.write('\r');
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastButtonState = buttonState;
if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
Serial.flush();
Serial.end();
Serial.begin(9600);
Serial.flush();
}
and i get something like this on serial:
on
number of button pushes = 1
on
number of button pushes = 2
on
number of button pushes = 3
on
number of button pushes = 4
on
number of button pushes = 5
etc.
and i want to get:
on
number of button pushes = 1 ----- and on this line 1 to be replaced with 2 at the next count, then with 3 and so on..
I have tryed Serial.print( '\r' ) for carryege return but didnt workt.
Can someone tell me where im wrong?? Or what i need to print so see what i want.