int topleft;
int topright;
int downleft;
int downright;
int waittime = 1;
void setup() {
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(6,OUTPUT);
TCCR1A = 0;
TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11);
TCCR1B = 0;
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11);
ICR1 = 40000;
OCR1A = 3000;
OCR1B = 3600;
}
void loop() {
digitalWrite(6,HIGH);
delay(30);
digitalWrite(6,LOW);
delay(1000);
topleft = analogRead(A0);
topright = analogRead(A1);
downleft = analogRead(A2);
downright = analogRead(A3);
if (topleft > topright) {
OCR1A = OCR1A + 1;
delay(waittime);
}
if (downleft > downright) {
OCR1A = OCR1A + 1;
delay(waittime);
}
if (topleft < topright) {
OCR1A = OCR1A - 1;
delay(waittime);
}
if (downleft < downright) {
OCR1A = OCR1A - 1;
delay(waittime);
}
if (OCR1A > 4000) {
OCR1A = 4000;
}
if (OCR1A < 2000) {
OCR1A = 2000;
}
if (topleft > downleft) {
OCR1B = OCR1B - 1;
delay(waittime);
}
if (topright > downright) {
OCR1B = OCR1B - 1;
delay(waittime);
}
if (topleft < downleft) {
OCR1B = OCR1B + 1;
delay(waittime);
}
if (topright < downright) {
OCR1B = OCR1B + 1;
delay(waittime);
}
if (OCR1B > 4200) {
OCR1B = 4200;
}
if (OCR1B < 3000) {
OCR1B = 3000;
}
}
Comments