Advertisement
j0h

robotIRControl

j0h
Jun 26th, 2023
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #include <IRremote.h>
  2.  
  3. const int RECV_PIN = 0; //ir remote
  4. IRrecv irrecv(RECV_PIN);
  5. decode_results results;
  6. //motor drive pins
  7. int m1FW=1;
  8. int m1RV=2;
  9. int m2FW=3;
  10. int m2RV=4;
  11.  
  12. //kill all function halt
  13. void halt();
  14.  
  15. //directional function prototypes
  16. void fw();
  17. void rv();
  18. void left();
  19. void right();
  20.  
  21. //run time==dtime
  22. int dtime=500; //in ms
  23. void setup() {
  24.   irrecv.enableIRIn(); // Start the receiver
  25.   irrecv.blink13(true);
  26. Serial.begin(9600);
  27.  pinMode(m1FW, OUTPUT);
  28.   pinMode(m1RV, OUTPUT);
  29.    pinMode(m2FW, OUTPUT);
  30.     pinMode(m2RV, OUTPUT);
  31. }
  32. // lets make a fire!
  33. void loop() {
  34. halt();
  35.  if (irrecv.decode(&results)) {
  36.  Serial.println(results.value);
  37.  
  38.  if(results.value==16732335){
  39.   //fw:16732335
  40.   fw();
  41.   }
  42.  if(results.value==16738455){
  43.   //rv: 16738455
  44.   rv();
  45.   }
  46.  if(results.value==16762935){
  47.   //rg:16762935
  48.   right();
  49.   }
  50.  if(results.value==16746615){
  51.   //lf:16746615
  52.   left();
  53.   }    
  54.   }
  55.    irrecv.resume(); // Receive the next value
  56.    
  57. }
  58. void left(){
  59.   digitalWrite(m1FW, HIGH);
  60.   digitalWrite(m2FW,HIGH);  
  61.   delay(dtime);               // wait for a second
  62.   halt();
  63.   }
  64.  
  65. void right(){
  66.   digitalWrite(m1RV, HIGH);
  67.   digitalWrite(m2RV,HIGH);  
  68.   delay(dtime);               // wait for a second
  69.   halt();
  70.   }
  71.  
  72. void rv(){
  73.   digitalWrite(m1FW, HIGH);
  74.   digitalWrite(m2RV,HIGH);  
  75.   delay(dtime);               // wait for a second
  76.   halt();
  77.   }
  78.  
  79. void fw(){
  80.   digitalWrite(m1RV, HIGH);
  81.   digitalWrite(m2FW,HIGH);  
  82.   delay(dtime);               // wait for a second
  83.   halt();
  84.   }
  85.  
  86. void halt(){
  87.   //stop all that sht
  88.    digitalWrite(m1FW, LOW);
  89.    digitalWrite(m1RV, LOW);
  90.    digitalWrite(m2FW, LOW);
  91.    digitalWrite(m2RV, LOW);
  92.  
  93.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement