정보나눔

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

적외선 레이더 급합니다 ㅜㅜ
이승원 | 2016-11-24

프로젝트 중 적외선레이더 에서 제공해주신 소스코드

/*
luckylarry.co.uk
Radar Screen Visualisation for Sharp GP2Y0A02 IR range finder
Sends sensor readings for every degree moved by the servo
values sent to serial port to be picked up by Processing
*/

#include // include the standard servo library
Servo leftRightServo;         // set a variable to map the servo
int leftRightPos = 0;         // set a variable to store the servo position
const int numReadings = 10;   // set a variable for the number of readings to take
int index = 0;                // the index of the current reading
float total = 0;              // the total of all readings must be a float to allow totaling of float values
int average = 0;              // the average
int IRpin = 1;                // analog pin for reading the IR sensor

/* setup the pins, servo and serial port */
void setup() {
  leftRightServo.attach(9);
  // initialize the serial port:
  Serial.begin(9600);
}

/* begin rotating the servo and getting sensor values */
void loop() {
  for(leftRightPos = 0; leftRightPos < 180; leftRightPos++) {  // going left to right.                               
    leftRightServo.write(leftRightPos);            
      for (index = 0; index<=numReadings;index++) {            // take x number of readings from the sensor and average them
        float volts = analogRead(IRpin)*0.0048828125;          // value from sensor*(5/1024) - if running 3.3.volts then change 5 to 3.3
        float distance = 65*pow(volts, -1.10);                 // worked out from graph 65 = theretical distance / (1/Volts)S
        total = total + distance;                              // update total
        delay(20);
      }
    average = (int) total/numReadings;                         // create average reading CAST TO INT!! remove the decimal places

    if (index >= numReadings)  {                               // reset the counts when at the last item of the array   
      index = 0;          
      total = 0;    
    }
    Serial.print("X");                                         // print leading X to mark the following value as degrees
    Serial.print(180-leftRightPos);                                // current servo position
    Serial.print("V");                                         // preceeding character to separate values
    Serial.println(average);                                   // average of sensor readings
  }
  /*
  start going right to left after we got to 180 degrees
  same code as above
  */
  for(leftRightPos = 180; leftRightPos > 0; leftRightPos--) {  // going right to left                               
    leftRightServo.write(leftRightPos);            
    for (index = 0; index<=numReadings;index++) {
      float volts = analogRead(IRpin)*0.0048828125;            // value from sensor*(5/1024) - if running 3.3.volts then change 5 to 3.3
      float distance = 65*pow(volts, -1.10);                   // worked out from graph 65 = theretical distance / (1/Volts)S
      total = total + distance;
      delay(20);
    }
    average = (int) total/numReadings; 
    if (index >= numReadings)  {          
      index = 0;          
      total = 0;    
    }
    Serial.print("X");
    Serial.print(180-leftRightPos);
    Serial.print("V");
    Serial.println(average);
   } 
}
를 아두이노에서 제공하는 툴로 돌렸는데

오류가 뜹니다.

exit status 1
#include expects "FILENAME" or <FILENAME>
라구요. 여러분 수정해봐도 안되는데 어떻게 해야할까요.

이전글   |    아두이노와 앱인벤터간의 블루통신 질문입니다.... 2016-11-23
다음글   |    아날로그 mapping 함수 질문있습니다. 2016-11-24