Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include <IRremote.h>
- Servo myservo;
- int pos = 90;
- int sens1 = A1;
- int sens2 = A0;
- int tolerance = 20;
- bool Aan_uit = 0;
- int state = 0;
- const int RECV_PIN1 = 11;
- IRrecv irrecv1(RECV_PIN1);
- decode_results results1;
- void setup()
- {
- myservo.attach(9);
- pinMode(sens1, INPUT);
- pinMode(sens2, INPUT);
- myservo.write(pos);
- Serial.begin(9600);
- irrecv1.enableIRIn();
- irrecv1.blink13(true);
- }
- void loop()
- {
- if (irrecv1.decode(&results1)){irrecv1.resume();}
- int val1 = analogRead(sens1);
- int val2 = analogRead(sens2);
- if (results1 == 0xFFA25D){Aan_uit = 1;}
- else{Aan_uit = 0;}
- )
- if ((abs(val1 - val2) <=tolerance) || (abs(val2 - val1) <= tolerance))
- {
- //do nothing if the difference between values is within the tolerance limit
- }
- else
- {
- if(val1 > val2)
- {
- pos - ++pos;
- }
- else if(val1 < val2)
- {
- pos = --pos;
- }
- }
- if(pos > 170) { pos = 170; }
- if(pos < 0) { pos = 0; }
- myservo.write(pos);
- delay(50);
- if (irrecv1.decode(&results1)){
- Serial.println(results1.value, HEX);
- irrecv1.resume();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement