정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

컴파일오류
Jeipeo | 2018-01-21

# include <servo.h>
servo myservo;
int sw = 5;
int angle = O;
long bounceStartTime = 0 ;
long debounce =50;
void setup()
{
  myservo.attach(3);
  pinMode(sw,INPUT_PULLUP);
}
void loop()
{
  if(digitalRead(sw) == LOW)
  {
    if(bounceStatTime == 0)
    {
      bounceStartTime = millis() ;
    }
    if(millis() - bounceStartTime > debounce)
    {
     angle += 15 ;
     if(angle > 180{
      angle = 0;
     }
     myservo.write(angle);
     bounceStartTime = 0;
     delay(1000) ;
    }
  }
}

지니어스 우노 컴파일 오류떠요 해결방안좀 알려주세요

프로필사진

하늘 2018-01-22 10:07:35

이 코드로 해 보세요

#include<Servo.h>
Servo myservo;
int sw=3;
int angle=0;
long bounceStartTime=0;
long debounce=50;
void setup() {
  // put your setup code here, to run once:
  myservo.attach(12);
  pinMode(sw,INPUT_PULLUP);
}
void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(sw)==LOW){
    if (bounceStartTime==0){
      bounceStartTime=millis();
      }
      if(millis()-bounceStartTime>debounce){
        angle+=20;
        if(angle<180){
        int angle=0;
      }
      myservo.write(angle);
      bounceStartTime==0;
     
    }
  }
}

 

제 생각에는 int angle = O;  0이 아니라 O가 드어가서 오류가 난것 같내요.

 

프로필사진

수박쨈 2018-01-22 14:36:00

위의 코드로 하시면 되는 듯 하네요!

이전글   |    카메라 전송 2018-01-20
다음글   |    블루투스로 서보모터 제어한 후 블루투스 연결 끊김... 2018-01-22