아하
학문

전기·전자

재빠른황로99
재빠른황로99

어떤 코드부분이 잘못된건가요?

제가 요새 팅커캐드를 통한 아두이노를 만들고 있는 중인데... 도저히 어떤 코드가 잘못되서 실행이 안되는건지...너무답답해서 글올려요ㅠㅡㅠ

(제 아두이노코드이니... 무단으로 퍼가시지 말아주세요...)


일단 제가 만들고 싶은건 어두울때 조도센서를 통해서 LED와 피에조 스피커가 같이 빛을 내며 소리를 내어 어두운것을 주위에게 알리는 것인데요... 아무리 시뮬레이션을 눌러도 피에조만 소리가 제멋대로 나고 조도센서랑 LED는 아예 작동도 안하구.. 뭐가 문제인지 알려주세요!

코드


// C++ code

//

int distance = 0;


long readUltrasonicDistance(int triggerPin, int echoPin)

{

pinMode(triggerPin, OUTPUT); // Clear the trigger

digitalWrite(triggerPin, LOW);

delayMicroseconds(2);

// Sets the trigger pin to HIGH state for 10 microseconds

digitalWrite(triggerPin, HIGH);

delayMicroseconds(10);

digitalWrite(triggerPin, LOW);

pinMode(echoPin, INPUT);

// Reads the echo pin, and returns the sound wave travel time in microseconds

return pulseIn(echoPin, HIGH);

}


void setup()

{

pinMode(A0, INPUT);

pinMode(13,OUTPUT);

Serial.begin(9600);

pinMode(6,OUTPUT);


}


void loop()

{

int var = analogRead(A0);

Serial.println(var);

if (var>600){

digitalWrite(13,HIGH);

digitalWrite(12,LOW);

}

if (var>800){

digitalWrite(13,LOW);

}

delay(200);

tone(6,659,600);


delay(600);


tone(6,587,500);


delay(500);


tone(6,523,400);


delay(400);


tone(6,587,400);


delay(400);


tone(6,659,700);


delay(700);


tone(6,659,700);


delay(700);


tone(6,659,100);


delay(100);


tone(6,587,800);


delay(800);


tone(6,587,800);


delay(800);


tone(6,587,100);


delay(100);


tone(6,659,700);


delay(700);


tone(6,659,700);


delay(700);


tone(6,659,100);


delay(100);


tone(6,659,600);


delay(600);


tone(6,587,400);


delay(400);


tone(6,523,600);


delay(600);


tone(6,587,700);


delay(700);


tone(6,659,800);


delay(800);


tone(6,659,800);


delay(800);


tone(6,659,800);


delay(800);


tone(6,587,600);


delay(600);


tone(6,587,600);


delay(600);


tone(6,659,800);


delay(800);


tone(6,587,600);


delay(600);


tone(6,523,500);


delay(500);


}


    1개의 답변이 있어요!
    전문가 답변 평가하기 이미지
    전문가 답변 평가답변의 별점을 선택하여 평가를 해주세요. 전문가들에게 도움이 됩니다.