정보나눔

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

스케치 오류 질문 제발 도와주세요 급해요!!ㅠㅠㅠㅠㅠ
김동주 | 2016-10-13

원래 스케치

 

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);
int trig1 = 6;
int trig2 = 7;
int echo1 = A0;
int echo2 = A1;
int LED1 = 8;
int LED2 = 9;
int LED3 = A2;
int Button1 = 13;
int Button2 = A3;
int state1 = 0;
int state2 = 0;
long distance;
long duration1;
long duration2;
long value1;
long value2;
void setup()
{
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(trig1, OUTPUT);
  pinMode(trig2, OUTPUT);
  pinMode(Button1, INPUT);
  pinMode(Button2, INPUT);
  pinMode(echo1, INPUT);
  pinMode(echo2, INPUT);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Push the Button");
  Serial.begin(9600);
}

void loop()
{
  state1 = digitalRead(Button1);
  state2 = digitalRead(Button2);

  if(state1 == HIGH)
  {
    digitalWrite(LED3,HIGH);
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("Scanning...");
    Ultrasonic1();
    Ultrasonic2();
    distance = value1+value2+16;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Dual MODE");
    lcd.setCursor(0, 1);
    lcd.print(distance.DEC);
    lcd.setCursor(3, 1);
    lcd.print("cm");
  }
  else if(state2 == HIGH)
  {
    digitalWrite(LED3,HIGH);
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("Scanning...");
    Ultrasonic1();
    distance = value1;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Single MODE");
    lcd.setCursor(0, 1);
    lcd.print(distance,DEC);
    lcd.setCursor(3, 1);
    lcd.print("cm");
  }
  else
  {
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,LOW);
  }
}

void Ultrasonic1()
{
  digitalWrite(trig1,LOW);                           
  delayMicroseconds(2);      
  digitalWrite(trig1,HIGH);   
  delayMicroseconds(5);
  digitalWrite(trig1,LOW);
  duration1 = pulseIn(echo1,HIGH);                
  value1 = microsecondsToCentimeters(duration1);
  delay(100);
}
void Ultrasonic2()
{
  digitalWrite(trig2,LOW);                           
  delayMicroseconds(2);      
  digitalWrite(trig2,HIGH);   
  delayMicroseconds(5);
  digitalWrite(trig2,LOW);
  duration2 = pulseIn(echo2,HIGH);                
  value2 = microsecondsToCentimeters(duration2);
  delay(100);
}
long microsecondsToCentimeters(long microseconds)
{
  return microseconds/29/2;
}

 

오류가 나는 부분

In file included from C:\Users\unso9\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.14\cores\arduino/Stream.h:26:0,

                 from C:\Users\unso9\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.14\cores\arduino/HardwareSerial.h:29,

                 from C:\Users\unso9\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.14\cores\arduino/Arduino.h:232,

                 from sketch\sketch_oct12a.ino.cpp:1:

C:\Users\unso9\OneDrive\Documents\Arduino\sketch_oct12a\sketch_oct12a.ino: In function 'void loop()':

C:\Users\unso9\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.14\cores\arduino/Print.h:29:13: error: expected unqualified-id before numeric constant

 #define DEC 10

             ^

C:\Users\unso9\OneDrive\Documents\Arduino\sketch_oct12a\sketch_oct12a.ino:57:24: note: in expansion of macro 'DEC'

     lcd.print(distance.DEC);

                        ^

exit status 1
보드 Arduino Nano 컴파일 에러.

이전글   |    ip주소를 이용하여 위치정보 사용 2016-10-13
다음글   |    안녕하세요 7세그먼트와 적외선 온도센서를 이용하여 만들려고 합니다.... 2016-10-14