标签:nic ras 代码 oop ros ultra usb inpu pre
一、准备材料。
开始制作:
1 #include <Servo.h> 2 3 #define Trig 7 4 #define Echo 6 5 6 Servo servo1; 7 8 int Duration; 9 float Distance; 10 int Distance1; 11 12 void setup() { 13 Serial.begin(9600); 14 servo1.attach(11); 15 pinMode(Trig, OUTPUT); 16 pinMode(Echo, INPUT); 17 } 18 19 void loop() { 20 Dis(); 21 while (Distance < 10) { 22 Dis(); 23 servo1.write(90); 24 delay(2500); 25 } 26 servo1.write(0); 27 delay(100); 28 } 29 30 void Dis() { 31 digitalWrite(Trig, LOW); 32 delayMicroseconds(1); 33 digitalWrite(Trig, HIGH); 34 delayMicroseconds(11); 35 digitalWrite(Trig, LOW); 36 Duration = pulseIn(Echo, HIGH, 10000); 37 if (Duration > 0) { 38 Distance = Duration / 2; 39 Distance = Distance * 340 / 10000; // ultrasonic speed is 340m/s = 34000cm/s = 0.034cm/us 40 Distance1 = Distance * 10; 41 } else { 42 Distance = 100; 43 } 44 }
12.
最后改装垃圾桶
标签:nic ras 代码 oop ros ultra usb inpu pre
原文地址:https://www.cnblogs.com/SkystarX/p/12286013.html