Pinguino IR Remote Robot

From Pinguino
Jump to: navigation, search

This project is work in progress.

Avengerbot

Source Code

 // This project is based on the Arduino library written by ken Shirriff
 // and modified for Pinguino by Régis Blanchot 
 // IR Remote Controlled Robot by Fred Warden
 // this PDE has been tested on the Pic18F4550 it use 88% of the ram
 // It does compile on the pic18F2550,pic18F47J53,pic18f26J50 but not tested yet.


 // IR remote Robot 2014
 // by Fred Warden
 // IR remote library ported by Régis Blanchot
 // orignial IR Arduino library by Ken Shirriff

 int RECV_PIN = 21;   // can be any digital pin
 

 int pinI1=3;//motor A
 int pinI2=4;//motor A
 int speedpinA=11;//enable motor A
 int pinI3=5;//motor B
 int pinI4=6;//motor B
 int speedpinB=12;//enable motor B

 int speeda=1023;//volume up
 int speedb=800;//volume up
 int speedc=760;//volume down
 int speedd=650;//volume down


decode_results results;
  
void setup()
{
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  pinMode(pinI3,OUTPUT);
  pinMode(pinI4,OUTPUT);
  pinMode(speedpinB,OUTPUT);
 
    

IRremote.enableIRIn(RECV_PIN); // Start the receiver

}

void loop(){ //start loop
    if (IRremote.decode(&results))     {
     
      if (results.value == 0x10) {     // volume up  ir values are derived from using decoderemote.pde example
       analogWrite(speedpinA,speeda);
       analogWrite(speedpinB,speeda);
      }
      if (results.value == 0x810){  // volume up
       analogWrite(speedpinA,speedb);
       analogWrite(speedpinB,speedb);
       }      
      if (results.value == 0x11) {   // volume down
       analogWrite(speedpinA,speedc);
       analogWrite(speedpinB,speedc);       
      }
      if (results.value == 0x811) {   // volume down
       analogWrite(speedpinA,speedd);
       analogWrite(speedpinB,speedd);
      }
    if (results.value == 0x81C||results.value == 0x1C) { //UP forward
     digitalWrite(pinI4,LOW);// Motor B 
     digitalWrite(pinI3,HIGH);
     digitalWrite(pinI2,LOW);// Motor A 
     digitalWrite(pinI1,HIGH);
    
    }       
      if (results.value == 0x81D||results.value == 0x1D) { //DOWN reverse
     digitalWrite(pinI4,HIGH);// Motor B 
     digitalWrite(pinI3,LOW);
     digitalWrite(pinI2,HIGH);// Motor A
     digitalWrite(pinI1,LOW);
      
     }
      if (results.value == 0x82B||results.value == 0x2B) { //LEFT
     digitalWrite(pinI4,LOW);//turn DC Motor B move clockwise
     digitalWrite(pinI3,HIGH);
     digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
     digitalWrite(pinI1,LOW);
     
     }
     if (results.value == 0x82C||results.value == 0x2C) { //RIGHT
     digitalWrite(pinI4,HIGH);// Motor B 
     digitalWrite(pinI3,LOW);
     digitalWrite(pinI2,LOW);// Motor A 
     digitalWrite(pinI1,HIGH);
      }
    
     if (results.value == 0x176||results.value == 0x976 ) { //STOP 
     digitalWrite(pinI4,LOW);// Motor B 
     digitalWrite(pinI3,LOW);
     digitalWrite(pinI2,LOW);// Motor A 
     digitalWrite(pinI1,LOW);
      
       
       
    }
    IRremote.resume(); // Receive the next value  
    
    }
}