Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // הגדרת מנוע סרוו לתנועות הפחדה
- #include <Servo.h>
- Servo handsServo;
- #define srvPin 10
- // משתנים לחיישן אולטראסוני
- #define trigPin 8
- #define echoPin 9
- long duration, distance;
- // נורות חיווי על מצב הפעלה
- #define powerOnLed 3
- #define yonaLed 4
- // משתנים של מפסקי גבול סוף מסילה
- #define startLSPin 5
- #define endLSPin 6
- int startLSValue = 0;
- int endLSValue = 0;
- //משתנים למנוע רכב רובוטי
- #define motorPin1 11
- #define motorPin2 12
- // משתנה לחיבור הזמזם
- #define buzPin 7
- // משתנה כיוון הנסיעה
- int dir = 0; // 0- back or stop, 1 - froward
- void setup() {
- Serial.begin(9600);
- handsServo.attach(srvPin);
- // מצב התחלתי של זרועות הדחליל
- handsServo.write(0);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- pinMode(powerOnLed, OUTPUT);
- // הדלק נורה כאשר יש מתח במערכת
- digitalWrite(powerOnLed, HIGH);
- pinMode(yonaLed, OUTPUT);
- // מצב התחלתי לא זוהתה יונה
- digitalWrite(yonaLed, LOW);
- pinMode(startLSPin, INPUT);
- pinMode(endLSPin, INPUT);
- pinMode(motorPin1, OUTPUT);
- pinMode(motorPin2, OUTPUT);
- digitalWrite(motorPin1, LOW);
- digitalWrite(motorPin2, LOW);
- }
- void loop() {
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = duration / 2 / 29.1;
- if (distance < 100) {
- //זוהתה יונה במרחק של פחות ממטר אחד
- endLSValue = digitalRead(endLSPin);
- // כל עוד הרכב לא היגיע לקצה המסילה תבצע את הפעולות הבאות
- while (endLSValue == LOW) {
- // הפעל מנועים בנסיעה קדימה
- digitalWrite(motorPin1, HIGH);
- digitalWrite(motorPin2, LOW);
- // הפעל זמזם להבריח יונים
- tone(buzPin, 4000);
- // הדלק נורת זיהוי יונה
- digitalWrite(yonaLed, HIGH);
- // הפעל מנוע ידי דחליל הלוך וחזור
- handsServo.write(90);
- delay(200);
- handsServo.write(00);
- delay(200);
- // קרא מפסקי גבול כדי לוודא שהרכב נמצא בתחילת המסילה
- endLSValue = digitalRead(endLSPin);
- }
- // עצור מנועים עם ההגעה לקצה המסילה
- digitalWrite(motorPin1, LOW);
- digitalWrite(motorPin2, LOW);
- startLSValue = digitalRead(startLSPin);
- // כל עוד הרובוט לא שב עד קצה המסילה תבצע את הפעולות הבאות
- while (startLSValue == LOW) {
- // הפעל מנועים בנסיעה לאחור
- digitalWrite(motorPin1, LOW);
- digitalWrite(motorPin2, HIGH);
- // השתק זמזם
- noTone(buzPin);
- // כבה יונה חיווי על המסילה
- digitalWrite(yonaLed, LOW);
- // עצור ידי דחליל
- handsServo.write(0);
- delay(200);
- // קרא מפסקי גבול כדי לוודא שהרכב נמצא בתחילת המסילה
- startLSValue = digitalRead(startLSPin);
- }
- // עצור מנועים עם ההגעה לקצה המסילה
- digitalWrite(motorPin1, LOW);
- digitalWrite(motorPin2, LOW);
- }
- else {
- digitalWrite(yonaLed, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement