极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17155|回复: 1

要做一个垃圾桶结果程序出问题了帮忙看下丢啦啥字母

[复制链接]
发表于 2019-2-21 21:16:24 | 显示全部楼层 |阅读模式
#include ( Servo.h )
#define  trigpin 3
#define  echopin 2
Servo  servo;
int sound = 250;
void setup( ) {
  serial .begin (9600);
  pinmode(trigpin . output);
  pinmode(trigpin . input);
  servo.attach(4);
}
void loop( ) {
  Long duration, distance;
  digitalWrite(trigpin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigpin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigpin, LOW);
  duration = pulseln (echopin, HIGH);
  distance = (duration/2)/29.1;
  if  (distance < 5) {
    Serial.println("the diatance is less than 5");
    servo . write ( 90 ) ;
  }
  else{
    servo.write(0);
  }
  if ( distance > 60  distance <=0){
    Serial . println ( " The distance is more than 60 ") ;
  }
  Else{
    Serial.print(distance);
    Serial . println ( "cm " ) ;
  }
  delay(500);
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2019-2-22 17:03:36 | 显示全部楼层
  1. #include "Servo.h"
  2. #define  trigpin 3
  3. #define  echopin 2
  4. Servo  servo;
  5. int sound = 250;
  6. void setup( ) {
  7.   Serial .begin (9600);
  8.   pinMode(trigpin,OUTPUT);
  9.   pinMode(trigpin,INPUT);
  10.   servo.attach(4);
  11. }
  12. void loop( ) {
  13.   long duration, distance;
  14.   digitalWrite(trigpin, LOW);
  15.   delayMicroseconds(2);
  16.   digitalWrite(trigpin, HIGH);
  17.   delayMicroseconds(10);
  18.   digitalWrite(trigpin, LOW);
  19.   duration = pulseIn(echopin, HIGH);
  20.   distance = (duration/2)/29.1;
  21.   if  (distance < 5) {
  22.     Serial.println("the diatance is less than 5");
  23.     servo . write ( 90 ) ;
  24.   }
  25.   else{
  26.     servo.write(0);
  27.   }
  28.   if ( distance > 60){
  29.     Serial . println ( " The distance is more than 60 ") ;
  30.   }
  31.   else{
  32.     Serial.print(distance);
  33.     Serial . println ( "cm " ) ;
  34.   }
  35.   delay(500);
  36. }
复制代码

不知道你这写得对不对。但是语法错误不少。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-27 02:41 , Processed in 0.043583 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表