من تغییرات تو برنامه رو ایجاد کردم اگه امکان داره بازبینی بفرمایید و سناریو به این شکله ک
1.اگر کلید A در حالت HIGH باشه و مقدار جاری زمان از زمان قبلی بیشتر از مقدار تایم(یک ساعت)بیشتر بشه رله چپ گرد رو روشن کنه و چهار چوب بره به سمت کلید B
2.حالا تو if چهارم گفتیم به محض رسیدن چهارچوب به کلید B, رله چپ گرد خاموش شه
3.اگر کلید َB در حالت HIGH باشه و مقدار جاری زمان از زمان قبلی بیشتر از مقدار تایم(یک ساعت)بیشتر بشه رله راست گرد رو روشن کنه و چهار چوب بره به سمت کلید A
4.حالا تو if سوم گفتیم به محض رسیدن چهارچوب به کلید A, رله راست گرد خاموش شه
کد:const int button_A = 2; //pin for button A const int button_B = 3; //pin for button B const int relay_L = 4; //pin for Left turn motor const int relay_R = 5; //pin for Right turn motor unsigned long previousMillis = 0; // will store last time button was updated long OffTime = 3600000; // milliseconds of off-time void setup() { pinMode(button_A,INPUT); pinMode(button_B,INPUT); pinMode(relay_L,OUTPUT); pinMode(relay_R,OUTPUT); } void loop() { unsigned long currentMillis = millis(); if((digitalRead(button_A)==HIGH) && (currentMillis - previousMillis >= OffTime)) { previousMillis = currentMillis; // Remember the time digitalWrite(relay_L,HIGH); //if curr-perv>=3600sec(1h) start turn motor to Left } if((digitalRead(button_B)==HIGH) && (currentMillis - previousMillis >= OffTime)) { previousMillis = currentMillis; // Remember the time digitalWrite(relay_R,HIGH); //if curr-perv>=3600sec(1h) start turn motor to Right } if(digitalRead(button_A)==HIGH) { digitalWrite(relay_R,LOW); ////stop motor turn Right after push button_A } if(digitalRead(button_B)==HIGH) { digitalWrite(relay_L,LOW); //stop motor turn Left after push button_B } }


9 لایک
LinkBack URL
About LinkBacks



پاسخ با نقل قول
