Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IRremote.h>
- const int RECV_PIN = 0; //ir remote
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- //motor drive pins
- int m1FW=1;
- int m1RV=2;
- int m2FW=3;
- int m2RV=4;
- //kill all function halt
- void halt();
- //directional function prototypes
- void fw();
- void rv();
- void left();
- void right();
- //run time==dtime
- int dtime=500; //in ms
- void setup() {
- irrecv.enableIRIn(); // Start the receiver
- irrecv.blink13(true);
- Serial.begin(9600);
- pinMode(m1FW, OUTPUT);
- pinMode(m1RV, OUTPUT);
- pinMode(m2FW, OUTPUT);
- pinMode(m2RV, OUTPUT);
- }
- // lets make a fire!
- void loop() {
- halt();
- if (irrecv.decode(&results)) {
- Serial.println(results.value);
- if(results.value==16732335){
- //fw:16732335
- fw();
- }
- if(results.value==16738455){
- //rv: 16738455
- rv();
- }
- if(results.value==16762935){
- //rg:16762935
- right();
- }
- if(results.value==16746615){
- //lf:16746615
- left();
- }
- }
- irrecv.resume(); // Receive the next value
- }
- void left(){
- digitalWrite(m1FW, HIGH);
- digitalWrite(m2FW,HIGH);
- delay(dtime); // wait for a second
- halt();
- }
- void right(){
- digitalWrite(m1RV, HIGH);
- digitalWrite(m2RV,HIGH);
- delay(dtime); // wait for a second
- halt();
- }
- void rv(){
- digitalWrite(m1FW, HIGH);
- digitalWrite(m2RV,HIGH);
- delay(dtime); // wait for a second
- halt();
- }
- void fw(){
- digitalWrite(m1RV, HIGH);
- digitalWrite(m2FW,HIGH);
- delay(dtime); // wait for a second
- halt();
- }
- void halt(){
- //stop all that sht
- digitalWrite(m1FW, LOW);
- digitalWrite(m1RV, LOW);
- digitalWrite(m2FW, LOW);
- digitalWrite(m2RV, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement