From af269dd20ab5af0a96926f9f7ee693b61114713b Mon Sep 17 00:00:00 2001 From: clf3 Date: Tue, 5 Sep 2023 20:39:59 +0800 Subject: [PATCH] time calculation --- radar/radar.ino | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/radar/radar.ino b/radar/radar.ino index 0b3c9e8..fd9f219 100644 --- a/radar/radar.ino +++ b/radar/radar.ino @@ -23,7 +23,7 @@ int outcircle=80; int midcircle=60; int midcircle2=40; int incircle=20; - +unsigned long time=0; Servo baseServo; Ucglib_ST7735_18x128x160_HWSPI ucg(/*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8); @@ -35,7 +35,7 @@ void setup(void) pinMode(trigPin, OUTPUT); //设置trigPin端口模式 pinMode(echoPin, INPUT); //设置echoPin端口模式 - Serial.begin(115200); //设置串口传输率 + Serial.begin(9600); //设置串口传输率 baseServo.attach(ServoPin); //初始化舵机 //欢迎屏幕 @@ -195,8 +195,10 @@ void loop(void) fix(); fix_font(); //重绘屏幕背景元素 - - for (int x=180; x > 4; x-=2){ //底座舵机从180~0度循环 + Serial.print("clear:"); + Serial.println(millis()-time); + time=millis(); + for (int x=180; x >= 0; x-=2){ //底座舵机从180~0度循环 baseServo.write(x); //调整舵机角度 @@ -228,9 +230,9 @@ void loop(void) //调试代码,输出角度和测距值 - Serial.print(x); - Serial.print(" , "); - Serial.println(distance); + //Serial.print(x); + //Serial.print(" , "); + //Serial.println(distance); //if (x > 70 and x < 110) fix_font(); //扫描线和数字重合时,重绘数字 @@ -247,14 +249,19 @@ void loop(void) // ucg.print("cm "); //delay(10); } + Serial.print("left:"); + Serial.println(millis()-time); + time=millis(); ucg.clearScreen(); //清屏 如果arduino供电不足,可能会引起白屏(显示信号中断)可以用 cls();函数代替 ucg.clearScreen(); delay(50); //cls(); //如有频繁白屏情况,可以使用该函数 。或者增加外部供电 fix(); fix_font(); //重绘屏幕背景元素 - - for (int x=1; x < 176; x+=2){ + Serial.print("clear:"); + Serial.println(millis()-time); + time=millis(); + for (int x=0; x <= 180; x+=2){ baseServo.write(x); //调整舵机角度 //绘制雷达扫描线 @@ -284,9 +291,9 @@ void loop(void) } //调试代码,输出角度和测距值 - Serial.print(x); - Serial.print(" , "); - Serial.println(distance); + //Serial.print(x); + //Serial.print(" , "); + //Serial.println(distance); //if (x > 70 and x < 110) fix_font(); //扫描线和数字重合时,重绘数字 @@ -302,9 +309,12 @@ void loop(void) // ucg.print("cm "); //delay(10); } - ucg.clearScreen(); // - delay(50); - //cls(); + Serial.print("right:"); + Serial.println(millis()-time); + time=millis(); + ucg.clearScreen(); // + delay(50); + //cls(); } \ No newline at end of file