에듀이노-코딩교육 전문 쇼핑몰 에듀이노-코딩교육 전문 쇼핑몰

학교, 공공기관이라면 후불결제하세요!

 
현재 위치
  1. 게시판
  2. 묻고답하기

묻고답하기

기술문의 게시판입니다.

게시판 상세
제목 예제파일 질문
작성자 (ip:)
  • 작성일 2020-11-13
  • 추천 추천하기
  • 조회수 83
안녕하세요 에듀이노 개발팀입니다.

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

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

감사합니다.

[ 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;

}



게시글 신고하기

신고사유

신고해주신 내용은 쇼핑몰 운영자의 검토 후 내부 운영 정책에 의해 처리가 진행됩니다.

평점 0점
첨부파일
비밀번호 수정 및 삭제하려면 비밀번호를 입력하세요.
댓글 수정

비밀번호 :

수정 취소

/ byte

비밀번호 : 확인 취소

댓글 입력

댓글달기이름 :비밀번호 : 관리자답변보기

확인

/ byte

왼쪽의 문자를 공백없이 입력하세요.(대소문자구분)

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

댓글 입력

댓글달기이름 :비밀번호 :

확인

/ byte

왼쪽의 문자를 공백없이 입력하세요.(대소문자구분)

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

«
»