Drgnslyrdlc

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.2 kB
0
Indexable
Never
#define rkpsol A3 #define rkpsag A2 #define zmn1 A0 #define zmn2 A1 #define INA1 4 #define INA2 5 #define INB1 7 #define INB2 8 #define PWM1 3 #define PWM2 9 #define tkt1 A4 #define tkt2 A5 int x = 0; int y = 0; int m = 0; int n = 0; int c = 0; int d = 0; void setup() { pinMode(tkt1, INPUT); pinMode(tkt2, INPUT); pinMode(rkpsag, INPUT); pinMode(rkpsol, INPUT); pinMode(INA1, OUTPUT); pinMode(INA2, OUTPUT); pinMode(INB1, OUTPUT); pinMode(INB2, OUTPUT); pinMode(PWM1, INPUT); pinMode(PWM2, INPUT); Serial.begin(9600); } void loop() { delay(4800); while(1){ zemin(); rakip(); } } void rakip() { if (digitalRead(rkpsol) == 1 and digitalRead(rkpsag) == 0) { motor(255, -255); } if (digitalRead(rkpsol) == 0 and digitalRead(rkpsag) == 1) { motor(-255, 255); } if (digitalRead(rkpsol) == 0 and digitalRead(rkpsag) == 0) { motor(255, 255 ); } } void deger() { x = analogRead(zmn1); y = analogRead(zmn2); Serial.print("zmn1="); Serial.print(x); Serial.print(" "); Serial.print("zmn2="); Serial.print(y); Serial.print(" "); n = digitalRead(rkpsag); m = digitalRead(rkpsol); Serial.print("rkpsag="); Serial.print(n); Serial.print(" "); Serial.print("rkpsol="); Serial.print(m); Serial.println(" "); Serial.print("tkt1="); Serial.print(c); Serial.print(" "); Serial.print("tkt2="); Serial.print(d); Serial.print(" "); } void motor(int a, int b) { if (a <= 0) { digitalWrite(INA1, 0); digitalWrite(INA2, 1); analogWrite(PWM1, abs(a)); } else { digitalWrite(INA1, 1); digitalWrite(INA2, 0); analogWrite(PWM1, a); } if (b <= 0) { digitalWrite(INB1, 0); digitalWrite(INB2, 1); analogWrite(PWM2, abs(b)); } else { digitalWrite(INB1, 1); digitalWrite(INB2, 0); analogWrite(PWM2, b); } } void zemin() { deger(); if (100 > analogRead(zmn1) and 100 > analogRead(zmn2)) { motor(0, 0); delay(50); motor(-255, -255); delay(450); motor(-255, 255); delay(160); } else if (100 > analogRead(zmn1) and 600 < analogRead(zmn2)) { motor(0, 0); delay(50); motor(-255, -255); delay(450); motor(255, -255); delay(160); } else if (600<analogRead(zmn1) and 100>analogRead(zmn2)) { motor(0, 0); delay(50); motor(-255, -255); delay(450); motor(-255, 255); delay(160); } else if (600 < analogRead(zmn1) and 600 < analogRead(zmn2)) { motor(200, 200); } else { motor(255, 255); } }