1

I'm having a problem. I want to clear the screen on the connected console. And after the clear, I want to rerun my code. But I can't seem to figure out how to do it. Below is some part of the code:

#include <motorStyring.h>
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#define PORT 6666
motorStyring mt;
int cm;
 YunServer server(PORT);
 const int pingPin = 9;
 int led = 13;
 void setup() {
 Serial.begin(115200);
 Bridge.begin();
 server.noListenOnLocalhost();
 server.begin();
 }
 void loop() {
 long duration, inches, cm;
 pinMode(pingPin,OUTPUT);
 digitalWrite(pingPin,LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin,LOW);
 pinMode(pingPin, INPUT);
 duration = pulseIn(pingPin,HIGH);
 cm = microsecondsToCentimeters(duration);
 h();
 }
 void h()
 {
 YunClient client = server.accept();
 if (client.connected()) {
 String question = "What would you like to drink?\nyou have 4 choises:\n1)Juice\n2)Vodca\n3)Soda\n4)Mix\n";
client.write((uint8_t*)&question[0], question.length()); 
String response;
while (client.connected()) {
 if (client.available()) {
 char cmd = client.read();
 if (cmd == '\n') {
 break;
 } else {
 response += String(cmd);
 }
 }
}
if (response == "juice") {
 juice();
} else if (response == "vodka") {
 vodka();
} else if (response == "soda") {
 soda();
} else if (response == "mix") {
 mix();
} else {
 String error = "you didn't select anything that corrospond to an option. \n try agin";
 client.write((uint8_t*)&error[0], error.length());
 }
 String awnser = "Here is your " + response;
 client.write((uint8_t*)&awnser[0], awnser.length());
 }
 delay(1000);
}

...

Is there a way to clear the screen on the console, so that all of the text from the previous code is not disturbing the user?

Ghanima
4595 silver badges18 bronze badges
asked Apr 24, 2014 at 17:22

1 Answer 1

1

Perhaps you could count the number of lines in the console and the print out enough carriage returns ("\n") to fill it with empty whitespace.

For example, with a console with 100 lines:

for(int iter = 0; iter < 100; iter++) {
 client.write('\n');
}
answered May 6, 2014 at 13:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.