تایمر اردوینو

Collapse
X
 
  • زمان
  • نمایش
Clear All
new posts
  • ghost.irib
    • 2020/05/29
    • 20

    #1

    تایمر اردوینو

    سلام خسته نباشید کسی میتونه تو این موضوع کمک کنه
    میخوام که اردوینو بعد از دوبار روشن کردن ال ای دی شروع کنه بعد از پنج ساعت یه رله رو فعال کنه یه کد نوشتم اما چون زمانبره میخوام شما اساتید چک کنید ببینید مشکلی داره یا درسته

    int LED = 6;
    int relay = 5;
    int sc = 0;
    int hr = 0;

    void setup(){
    Serial.begin(9600);

    pinMode(LED, OUTPUT);
    }

    void loop(){
    while (sc < 2){
    digitalWrite(LED, HIGH);
    delay (500);
    digitalWrite(LED, LOW);
    delay (500);
    sc++;
    while (hr < 5){
    digitalWrite(LED, HIGH);
    delay (1800000);
    digitalWrite(LED, LOW);
    delay (1800000);
    hr++;
    }
    }
    }


  • ghost.irib
    • 2020/05/29
    • 20

    #2
    پاسخ : تایمر اردوینو

    یعنی کسی نیست کمک کنه ؟

    دیدگاه

    • hossein.m98
      • 2017/06/13
      • 1400

      #3
      پاسخ : تایمر اردوینو

      نوشته اصلی توسط ghost.irib
      یعنی کسی نیست کمک کنه ؟
      سلام
      اگر دقت براتون مهمه، باید بگم این تابع دقت خوبی نداره! بهتره با تایمر پیاده سازی اش کنید. اصلا نمیدونم میشه همچین تاخیری با تابع delay ایجاد کرد یا نه. تابع delay برای کارای دم دستی و نهایت برای چند ثانیه ساخته شده؛ به خاطر همین دقت خوبی هم نداره. توی کار حرفه ای نمیذارن میکروکنترلر نیم ساعت درگیر تابع delay باشه و میبرنش به مد Sleep.

      دیدگاه

      • ghost.irib
        • 2020/05/29
        • 20

        #4
        پاسخ : تایمر اردوینو

        پس چکار کنم برای تایمر ؟

        دیدگاه

        • hossein.m98
          • 2017/06/13
          • 1400

          #5
          پاسخ : تایمر اردوینو

          نوشته اصلی توسط ghost.irib
          پس چکار کنم برای تایمر ؟
          اگر دقت زیاد براتون مهم نباشه همینم اوکیه. نه اگر تایمر میخوایید باشه، یه سرچی بزنید توی اینترنت پر از آموزشه.

          دیدگاه

          • saeed bagherani
            • 2007/02/18
            • 2573

            #6
            پاسخ : تایمر اردوینو

            بهتره یک زیر برنامه بنویسین با پالس های 1 ثانیه
            وقتی تعدا پالس مورد نظر رسید اون موقع کار مورد نظر انجام بشه
            نه میکرو درگیره و ....

            در واقع از یک شمارنده استفاده می کنید که پالسهای 1 ثانیه توسط خود میکرو تولید می شه





            دلیل: ادغام دو پست برای جلوگیری از اسپم

            به این برنامه دقت کنید





            const int InternalLed = LED_BUILTIN;// the number of the LED pin
            int ledState = LOW; // ledState used to set the LED


            unsigned long PreviueMiliSecond1000 = 0 ; // will store last time LED was updated
            unsigned long PreviueMiliSecond500 = 0;
            unsigned long PreviueMiliSecond100 = 0;
            unsigned long PreviueMiliSecond10 = 0;
            unsigned long PreviueMiliSecond1 = 0;


            const unsigned long d1000 = 1000000;// interval at which to blink (1000 milliseconds)
            const unsigned long d500 = 500000;// interval at which to blink (500 milliseconds)
            const unsigned long d100 = 100000;// interval at which to blink (100 milliseconds)
            const unsigned long d10 = 10000;// interval at which to blink (10 milliseconds)
            const unsigned long d1 = 1000;// interval at which to blink (1 milliseconds)


            unsigned long timee;
            unsigned long c;


            void setup() {
            Serial.begin(250000);
            pinMode(InternalLed, OUTPUT);
            }


            void loop() {
            //---------------- loop 1s -----------
            unsigned long currentMillis1000 = micros(); if (currentMillis1000 - PreviueMiliSecond1000 >= d1000) {
            PreviueMiliSecond1000 = currentMillis1000;
            loop1000ms();
            }
            //---------------- loop 500ms -----------
            unsigned long currentMillis500 = micros(); if (currentMillis500 - PreviueMiliSecond500 >= d500) {
            PreviueMiliSecond500 = currentMillis500;
            loop500ms();
            }
            //---------------- loop 100ms -----------
            unsigned long currentMillis100 = micros(); if (currentMillis100 - PreviueMiliSecond100 >= d100) {
            PreviueMiliSecond100 = currentMillis100;
            loop100ms();
            }
            //---------------- loop 10ms -----------
            unsigned long currentMillis10 = micros(); if (currentMillis10 - PreviueMiliSecond10 >= d10) {
            PreviueMiliSecond10 = currentMillis10;
            loop10ms();
            }
            //---------------- loop 1ms -----------
            unsigned long currentMillis1 = micros(); if (currentMillis1 - PreviueMiliSecond1 >= d1) {
            PreviueMiliSecond1 = currentMillis1;
            loop1ms();
            }


            }


            void loop1000ms() {//------------------------------- loop 1000 ms ----------------------
            if (ledState == LOW) {
            ledState = HIGH;
            } else {
            ledState = LOW;
            } digitalWrite(InternalLed, ledState);
            c++;
            Serial.print(c );
            Serial.println(" 1000 ms isr" );
            }
            void loop500ms() {//------------------------------- loop 500 ms ----------------------
            c++;
            Serial.print(c );
            Serial.println(" 500 ms isr" );
            }
            void loop100ms() {//------------------------------- loop 100 ms ----------------------
            c++;
            Serial.print(c );
            Serial.println(" 100 ms isr" );
            }
            void loop10ms() {//------------------------------- loop 10 ms ----------------------
            c++;
            Serial.print(c );
            Serial.println(" 10 ms isr" );
            }


            void loop1ms() {//------------------------------- loop 1 ms ----------------------
            c++;
            Serial.print(c );
            Serial.println("1 ms " );
            }


            عیناا کپی کنید توی محیط آردوینو

            توی برخی قسمتها می تونی زمان سنجی مورد نظر رو بزاری

            اگه مردم می دونستن زمان چقدر با ارزشه دیگه هیچ وقت کفش بند دار نمی خریدن البرت انیشتن

            دیدگاه

            • ghost.irib
              • 2020/05/29
              • 20

              #7
              پاسخ : تایمر اردوینو

              ببخشید کسی میتونه یه تیکه کد با کتابخونه time.h بهم بده که ساعت و دیقه رو پرینت سریال کنه ؟

              دیدگاه

              لطفا صبر کنید...