element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products and Partners
    Products and Partners
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Community Hub
Community Hub
Member's Forum Arduino Serial
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Community Hub to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 21 replies
  • Subscribers 632 subscribers
  • Views 2346 views
  • Users 0 members are here
  • arduino serial stuff
Related

Arduino Serial

roby1
roby1 over 9 years ago

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.

  • Sign in to reply
  • Cancel
Parents
  • RParkerE
    RParkerE over 9 years ago

    Another "workaround" would be to figure out how many lines long the Arduino Serial Monitor is when you are using it and feed it that many line feeds effectively clearing the screen.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • balearicdynamics
    balearicdynamics over 9 years ago in reply to RParkerE

    Pter, I think that the Arduino Serial Monitor can't be managed in this way as this is - as a matter of fact - a java multi line text window that canbe resized as you want.

     

    What is needed is a terminal supporting ANSI Escapes, it is correct and in practice this means a terminal program (like the Linux term) that can be configured in VT100+ mode.

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • RParkerE
    RParkerE over 9 years ago in reply to balearicdynamics

    Yes I knew that it could be resized, however I thought it required a manual action. If you were not to manually resize the window I thought it could work as a "smoke and mirrors" fix. But I do agree that a terminal supporting ANSI Escapes is what is needed.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • balearicdynamics
    balearicdynamics over 9 years ago in reply to RParkerE

    IMHO there is another factor to be considered. By a usability point of view it has not too much sense to launche the Arduino IDE to run a (debug anf limited) terminal.

    This means that you can't use your project only in a computer where you had previoysly installed the Arduino development environment, that is very limiting.

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • balearicdynamics
    balearicdynamics over 9 years ago in reply to RParkerE

    IMHO there is another factor to be considered. By a usability point of view it has not too much sense to launche the Arduino IDE to run a (debug anf limited) terminal.

    This means that you can't use your project only in a computer where you had previoysly installed the Arduino development environment, that is very limiting.

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube