cm = (duration/2)/29.155; // Divide duration in half (due to round trip), then convert distance to centimeters (1cm per 29.155 microseconds), assign to cm variable Serial.print(cm); // Print distance in cm to s
Parameters of program functions: for example, in the time function: parameters of the delay function: ms: pause time, the time unit is milliseconds (unsigned long data), delay Microseconds function parameters: us: pause time, the time unit is microseconds (unsigned long data), millis, mircros...
* @param usec * Optionally pass pull-up time (in microseconds) before DHT reading * starts. Default is 55 (see function declaration in dht.h). * @return If read data successfully return DHTLIB_OK, * if the data are not complete return DHTLIB_ERROR_CHECKSUM, * if read timeout return ...
cm = microsecondsToCentimeters(duration); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(1000); } longmicrosecondsToCentimeters(longmicroseconds) { //The speed of sound is 340 m/s or 29 microseconds per centimeter. //The ping travels out and back, so to find the distance...
delay(ms) 暂停晶片执行多少毫秒 范例:delay(500); //暂停半秒(500毫秒) delay Microseconds(us) 暂停晶片执行多少微秒 范例:delayMicroseconds(1000); //暂停1豪秒 数学函式 三角函数以及基本的数学运算 min(x, y) 回传两数之间较小 范例:val = min(10,20); // 回传10 ...
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS)。 unsigned int dist = sonar.convert_cm(uS); // Convert into centimeters if(dist》=200 || dist《=0){ lcd.clear(); lcd.setCursor (0,1); // go to start of 2nd line ...
delay(1500);} 复制代码 这里我们只需要包含库,定义伺服对象,并使用attach()函数定义伺服所连接的引脚...
cm = microsecondsToCentimeters(duration); Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(100); } long microsecondsToInches(long microseconds) { return microseconds / 74 / 2; ...
#define RADAR A0 // RADAR inut is attached to A0 #define MICRODELAY 100 // 100microseconds ~10000hz #define MAXINDEX 1024 // 10 bits #define TOPINDEX 1023 // 10 bits byte collect[MAXINDEX]; int mean; int minimum; int maximum; ...
9、出引脚速度控制-使用Arduino的数字输出引脚-产生脉冲信号用EasyDriver驱动双极性步进电机voi d setup () pirJilode (dirFin, 0UTF1.IT):pirJilode(5 tapper Fin, OUTFUT): int stepperPin = 5;voi d loop 0 step (triiSj 1600): del ay (500);step (fals 1600*5):delay (500):voi d step (...