نمایش نتایج: از 1 به 2 از 2

موضوع: اشتباه کد کجاست ؟؟؟؟؟؟؟؟؟؟؟؟

  1. #1
    Member
    تاریخ عضویت
    May 2016
    نوشته ها
    94

    اشتباه کد کجاست ؟؟؟؟؟؟؟؟؟؟؟؟

    کد مربوط به التراسونیک و سنسور دماسنج ( هر دو با هم )

    کد :


    // 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;
    #define buzzer 6
    int sound ;
    float temp;
    int tempPin = 0;
    int buzzer1=8; //Connect the buzz positive Pin to Digital Pin 8

    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); // The set TrigPin output mode.
    pinMode(buzzer1,OUTPUT); //Set Pin Mode as output
    Serial.begin(9600);
    beep(500);

    }


    void loop() {

    // 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)) { // Pulse effective range (1, 60000).
    // Len_mm = (Time_Echo_us * 0.34mm/us) / 2 (mm)
    Len_mm = ((Time_Echo_us*34/100)/2);
    if( Len_mm<=1500)
    {
    sound=100;
    analogWrite(buzzer,sound);
    digitalWrite(buzzer, HIGH);
    digitalWrite(12, HIGH);

    }
    else
    {
    sound=0;
    //digitalWrite(buzzer, LOW)
    digitalWrite(12,LOW );
    digitalWrite(buzzer, 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
    }

    {
    //digitalWrite(buzzer,LOW);

    temp = analogRead(tempPin);
    temp = temp * 0.48828125;

    if(temp > 31) { beep(50); beep(50); }

    Serial.print("TEMPRATURE = ");
    Serial.print(temp);
    Serial.print(" Celcius");
    Serial.println();
    delay(1000);
    }


    void beep(unsigned char delayms){
    digitalWrite(buzzer1,HIGH);
    delay(delayms); // wait for a delayms ms
    digitalWrite(buzzer1,LOW);
    delay(delayms); // wait for a delayms ms
    }


    اشتباه کد کجاست ؟؟؟؟؟؟؟؟؟؟؟ ( برای اپلود کردن )

  2. #2
    مدیر گروه
    تاریخ عضویت
    Nov 2013
    محل سکونت
    ایران
    نوشته ها
    3,995
    باز هم مشکل پرانتز

    کد:
    
    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; 
    #define buzzer 6
    int sound ;
    float temp;
    int tempPin = 0;
    int buzzer1=8; //Connect the buzz positive Pin to Digital Pin 8 
    
    
    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); // The set TrigPin output mode.
    pinMode(buzzer1,OUTPUT); //Set Pin Mode as output
    Serial.begin(9600);
    beep(500);
    
    
    }
    
    
    
    
    void loop() { 
    
    
    // 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)) { // Pulse effective range (1, 60000).
    // Len_mm = (Time_Echo_us * 0.34mm/us) / 2 (mm) 
    Len_mm = ((Time_Echo_us*34/100)/2);
    if( Len_mm<=1500)
    {
    sound=100;
    analogWrite(buzzer,sound);
    digitalWrite(buzzer, HIGH);
    digitalWrite(12, HIGH);
    
    
    }
    else
    {
    sound=0;
    //digitalWrite(buzzer, LOW)
    digitalWrite(12,LOW );
    digitalWrite(buzzer, 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
    
    
    //digitalWrite(buzzer,LOW);
    
    
    temp = analogRead(tempPin);
    temp = temp * 0.48828125;
    
    
    if(temp > 31) { beep(50); beep(50); }
    
    
    Serial.print("TEMPRATURE = ");
    Serial.print(temp);
    Serial.print(" Celcius");
    Serial.println();
    delay(1000);
    }
    
    
    
    
    void beep(unsigned char delayms){
    digitalWrite(buzzer1,HIGH);
    delay(delayms); // wait for a delayms ms
    digitalWrite(buzzer1,LOW);
    delay(delayms); // wait for a delayms ms 
    }

مجوز های ارسال و ویرایش

  • شما نمیتوانید موضوع جدیدی ارسال کنید
  • شما امکان ارسال پاسخ را ندارید
  • شما نمیتوانید فایل پیوست کنید.
  • شما نمیتوانید پست های خود را ویرایش کنید
  •  

SEO by vBSEO