نوشته اصلی توسط
peyman180
سلام ببخشید اشتباه این کد کجاست ؟؟؟
کد:
ممنون میشم اگه جواب بدید ...
یه تعداد از سمی کالن ها رو یادتون رفته بود:
کد:
// US-100 Ultrasonic module in GPIO mode measuring the distance of the program
// Unplug the US-100 module jumper cap on the back.
unsigned int EchoPin = 2; // The Arduino's the Pin2 connection to US-100 Echo / RX
unsigned int TrigPin = 3; // The Arduino's Pin3 connected to US-100 Trig / TX
unsigned long Time_Echo_us = 0;
unsigned long Len_mm = 0;
unsigned int Len_Required;
#define buzzer 6
int sound ;
int key;
void setup() {
//Initialize
Serial.begin(9600); // The measurement results through the serial output to the serial port on the PC monitor
pinMode(EchoPin, INPUT); // The set EchoPin input mode.
pinMode(TrigPin, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(12, OUTPUT); // LED
pinMode(11, INPUT);
}
void loop() {
// WHAT'S THE STATUS OF KEY ???
key=digitalRead(11);
if(key==0){Len_Required=1500;}
else if(key==1){Len_Required=500;}
// By the Trig / Pin sending pulses trigger US-100 ranging
digitalWrite(TrigPin, HIGH); // Send pulses begin by Trig / Pin
delayMicroseconds(50); // Set the pulse width of 50us (> 10us)
digitalWrite(TrigPin, LOW); // The end of the pulse
Time_Echo_us = pulseIn(EchoPin, HIGH); // A pulse width calculating US-100 returned
if((Time_Echo_us < 60000) && (Time_Echo_us > 1))
{
Len_mm = ((Time_Echo_us*34/100)/2);
}
if(Len_mm <= Len_Required)
{
digitalWrite(buzzer, HIGH);
digitalWrite(12, HIGH);
}
else
{
digitalWrite(buzzer, LOW);
digitalWrite(12,LOW );
}
Serial.print("Present Distance is: "); // Output to the serial port monitor
Serial.print(Len_mm, DEC); // Output to the serial port monitor
Serial.println("mm"); // Output to the serial port monitor
delay(333); // Per second (1000ms) measured
}