에듀이노-아두이노 전문 교육쇼핑몰 에듀이노-코딩교육 전문 쇼핑몰
뒤로가기

묻고답하기

제목

예제파일 질문

작성자 (ip:)

작성일 2020-11-13

조회 87

평점 0점  

추천 추천하기

내용
안녕하세요 에듀이노 개발팀입니다.

현재 저희측에서 제공하는 자료에만 문의가 가능하며,

해당 코드는 코드구성형식이 전체적으로 검토가 필요합니다. {,} 또는 함수선언에 대한 문법을 고려하여 코드를 검토해주시기 바랍니다.

감사합니다.

[ Original Message ]


자율주행 모드를 테스트 하려고 하는데 자꾸 에러가 나네요 ㅜㅜ


오류메세지는


아두이노:1.6.12 (Mac OS X), 보드:"Arduino Uno"


/var/folders/qf/3xbcp_353d93lrwj5y4jnxl00000gn/T/arduino_modified_sketch_865481/MotorParty.pde: In function 'void loop()':

MotorParty:37: error: 'Ultrasonic' was not declared in this scope

   Ultra_d = Ultrasonic();

             ^~~~~~~~~~

/var/folders/qf/3xbcp_353d93lrwj5y4jnxl00000gn/T/arduino_modified_sketch_865481/MotorParty.pde:37:13: note: suggested alternative: 'Ultra_d'

   Ultra_d = Ultrasonic();

             ^~~~~~~~~~

             Ultra_d

MotorParty:53: error: 'Servo_con' was not declared in this scope

       val = Servo_con();

             ^~~~~~~~~

/var/folders/qf/3xbcp_353d93lrwj5y4jnxl00000gn/T/arduino_modified_sketch_865481/MotorParty.pde:53:13: note: suggested alternative: 'Servo_h'

       val = Servo_con();

             ^~~~~~~~~

             Servo_h

/var/folders/qf/3xbcp_353d93lrwj5y4jnxl00000gn/T/arduino_modified_sketch_865481/MotorParty.pde: In function 'void motor_role(int, int, int)':

MotorParty:85: error: a function-definition is not allowed here before '{' token

 int Ultrasonic(){

                 ^

MotorParty:96: error: a function-definition is not allowed here before '{' token

 int Servo_con() {

                 ^

MotorParty:113: error: expected '}' at end of input

 }

 ^

exit status 1

'Ultrasonic' was not declared in this scope


라고 뜨네요


예제를 보고 그대로 쓰긴했는데 밑에는 입력한 예제입니다



#include <Servo.h>

Servo EduServo;


int trigPin = 13;

int echoPin = 12;

int Ultra_d = 0;



int RightMotor_E_pin = 5;

int LeftMotor_E_pin = 6;

int RightMotor_1_pin = 8;

int RightMotor_2_pin = 9;

int LeftMotor_3_pin = 10;

int LeftMotor_4_pin = 11;


int motor_s = 160;

int val = 0;


void setup() {

  EduServo.attach(2);


  pinMode(echoPin, INPUT);

  pinMode(trigPin, OUTPUT);


  pinMode(RightMotor_E_pin, OUTPUT);

  pinMode(RightMotor_1_pin, OUTPUT);

  pinMode(RightMotor_2_pin, OUTPUT);

  pinMode(LeftMotor_3_pin, OUTPUT);

  pinMode(LeftMotor_4_pin, OUTPUT);

  pinMode(LeftMotor_E_pin, OUTPUT);


  Serial.begin(9600);

  Serial.println("Welcome Eduino!");

}


void loop() {

  Ultra_d = Ultrasonic();

  Serial.println(Ultra_d);

  motor_role(HIGH, HIGH, motor_s);


  if(Ultra_d < 250) {

    if (Ultra_d < 150) {

      Serial.println("150 이하");

      motor_role(LOW, LOW, motor_s);

      delay(1000);

      motor_role(HIGH, HIGH, 0);

      delay(200);

    }

    else {

      motor_role(HIGH, HIGH, 0);

      delay(200);

      Serial.println("150 이상.");

      val = Servo_con();

      if (val == 0) {

        Serial.println("우회전.");

        motor_role(HIGH, HIGH, 0);

        delay(500);

        motor_role(LOW, LOW, motor_s);

        delay(500);

        motor_role(LOW, HIGH, motor_s);

        delay(800);

      }

      else if (val == 1) {

        Serial.println("좌회전.");

        motor_role(HIGH, HIGH, 0);

        delay(500);

        motor_role(LOW, LOW, motor_s);

        delay(500);

        motor_role(HIGH, LOW, motor_s);

        delay(800);

      }

    }

  }

}


void motor_role(int R_motor, int L_motor, int Speed){

  digitalWrite(RightMotor_1_pin, R_motor);

  digitalWrite(RightMotor_2_pin, !R_motor);

  digitalWrite(LeftMotor_3_pin, L_motor);

  digitalWrite(LeftMotor_4_pin, !L_motor);


  analogWrite(RightMotor_E_pin, Speed);

  analogWrite(LeftMotor_E_pin, Speed);


int Ultrasonic(){

  long duration, distance;

  digitalWrite(trigPin, HIGH);

  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

  distance = ((float) (340 * duration) / 1000) / 2;


  return distance;

}


int Servo_con() {

  Eduservo.write(30);

  int Ult_30 = Ultrasonic();

  delay(1000);

  Eduservo.write(150);

  int Ult_150 = Ultrasonic();

  delay(1000);


  if(Ult_30 > Ult_150) {

    val = 1;

  }

  else{

    val = 0;

  }

  EduServo.write(90);


  return val;

}



첨부파일

비밀번호
수정

비밀번호 입력후 수정 혹은 삭제해주세요.

댓글목록

등록된 댓글이 없습니다.

댓글 수정

이름

비밀번호

내용

/ byte

수정 취소

비밀번호 :

확인 취소

댓글 입력

이름

비밀번호

내용

/ byte

평점

왼쪽의 문자를 공백없이 입력하세요.

에게만 댓글 작성 권한이 있습니다.

댓글 입력

이름

비밀번호

내용

/ byte

왼쪽의 문자를 공백없이 입력하세요.

에게만 댓글 작성 권한이 있습니다.

관련 글 보기

  • 비밀글 RC카 길이 늘리기 김종호 2024-03-24 0점 [자율주행 프로젝트 : 4휠 스마트카] 아두이노 코딩교육

  • 비밀글 안녕하세요 공과대전자 2024-03-21 0점 [자율주행 프로젝트 : 4휠 스마트카] 아두이노 코딩교육

고객센터

    1670-9626

  • 팩스.063-902-6678
  • 이메일.eduino@robodyne.co.kr
  • Kakao. 에듀이노
  • 운영시간 : AM 10:00 ~ PM 16:30
  • 점심시간 : PM 12:00 - PM 13:00 토/일/공휴일 휴무
  • 고객센터 연결하기
입금계좌
  • 예금주: (주)로보다인시스템
  • 국민. 754801-01-760296
  • 농협. 301-0234-1423-01
  • IBK기업은행. 506-080015-01-016
배송 안내
  • 배송 방법 : 택배
  • 배송 지역 : 전국지역
  • 배송 비용 : 조건부 무료 : 주문 금액 100,000원 미만일 때 배송비 3,000원을 추가합니다.
  • 배송 기간 : 1일 ~ 2일
  • 배송 안내 :
    - 제주도, 산간벽지나 도서지방은 별도의 추가금액을 지불하셔야 하는 경우가 있습니다.
    고객님께서 주문하신 상품은 입금 확인후 배송해 드립니다. 다만, 상품종류에 따라서 상품의 배송이 다소 지연될 수 있습니다.
교환/반품 안내
교환 및 반품이 가능한 경우
- 상품을 공급 받으신 날로부터 7일이내 단, 가전제품의
  경우 포장을 개봉하였거나 포장이 훼손되어 상품가치가 상실된 경우에는 교환/반품이 불가능합니다.
- 공급받으신 상품 및 용역의 내용이 표시.광고 내용과
  다르거나 다르게 이행된 경우에는 공급받은 날로부터 3월이내, 그사실을 알게 된 날로부터 30일이내

교환 및 반품이 불가능한 경우
- 고객님의 책임 있는 사유로 상품등이 멸실 또는 훼손된 경우. 단, 상품의 내용을 확인하기 위하여
  포장 등을 훼손한 경우는 제외
- 포장을 개봉하였거나 포장이 훼손되어 상품가치가 상실된 경우
  (예 : 가전제품, 식품, 음반 등, 단 액정화면이 부착된 노트북, LCD모니터, 디지털 카메라 등의 불량화소에
  따른 반품/교환은 제조사 기준에 따릅니다.)
- 고객님의 사용 또는 일부 소비에 의하여 상품의 가치가 현저히 감소한 경우 단, 화장품등의 경우 시용제품을
  제공한 경우에 한 합니다.
- 시간의 경과에 의하여 재판매가 곤란할 정도로 상품등의 가치가 현저히 감소한 경우
- 복제가 가능한 상품등의 포장을 훼손한 경우
  (자세한 내용은 고객만족센터 1:1 E-MAIL상담을 이용해 주시기 바랍니다.)

※ 고객님의 마음이 바뀌어 교환, 반품을 하실 경우 상품반송 비용은 고객님께서 부담하셔야 합니다.
  (색상 교환, 사이즈 교환 등 포함)
«
»