Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <Servo.h>
  2. #include <IRremote.h>
  3.  
  4. Servo myservo;
  5. int pos = 90;
  6. int sens1 = A1;
  7. int sens2 = A0;
  8. int tolerance = 20;
  9. bool Aan_uit = 0;
  10. int state = 0;
  11.  
  12. const int RECV_PIN1 = 11;
  13. IRrecv irrecv1(RECV_PIN1);
  14. decode_results results1;
  15.  
  16. void setup()
  17. {
  18. myservo.attach(9);
  19. pinMode(sens1, INPUT);
  20. pinMode(sens2, INPUT);
  21. myservo.write(pos);
  22. Serial.begin(9600);
  23. irrecv1.enableIRIn();
  24. irrecv1.blink13(true);
  25. }
  26.  
  27. void loop()
  28. {
  29. if (irrecv1.decode(&results1)){irrecv1.resume();}
  30. int val1 = analogRead(sens1);
  31. int val2 = analogRead(sens2);
  32. if (results1 == 0xFFA25D){Aan_uit = 1;}
  33. else{Aan_uit = 0;}
  34. )
  35. if ((abs(val1 - val2) <=tolerance) || (abs(val2 - val1) <= tolerance))
  36. {
  37. //do nothing if the difference between values is within the tolerance limit
  38. }
  39. else
  40. {
  41. if(val1 > val2)
  42. {
  43. pos - ++pos;
  44. }
  45. else if(val1 < val2)
  46. {
  47. pos = --pos;
  48. }
  49. }
  50.  
  51. if(pos > 170) { pos = 170; }
  52. if(pos < 0) { pos = 0; }
  53.  
  54. myservo.write(pos);
  55. delay(50);
  56. if (irrecv1.decode(&results1)){
  57. Serial.println(results1.value, HEX);
  58. irrecv1.resume();
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement