Mikanum/mecanum.ino
2023-01-19 08:45:51 +01:00

212 lines
4.4 KiB
C++

#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#define IR 4
IRrecv irrecv(IR);
#define WHEEL_FRONT_LEFT_F A0
#define WHEEL_REAR_LEFT_R A1
#define WHEEL_REAR_RIGHT_F A2
#define WHEEL_FRONT_RIGHT_R A3
#define WHEEL_FRONT_LEFT_R 10
#define WHEEL_REAR_LEFT_F 9
#define WHEEL_FRONT_RIGHT_F 8
#define WHEEL_REAR_RIGHT_R 7
/*
* 4060792887 ^
* 4060752087 v
* 4060768407 <
* 4060784727 >
* 4060801047 enter
* 4060776567 menu
* 4060774527 aspect
* 4060745967 vol+
* 4060794927 vol-
* 4060803087 mute
* 4060750047 source
* 4060790847 video mode
* 4060786767 keystone +
* 4060778607 keystone -
* 4060782687 mouse +
* 4060766367 mouse -
* 4060748007 auto adj
* 4060743927 freeze
* 4060754127 blank
* 4060762287 zoom +
* 4060770447 zoom -
* 4060759227 info
* 4060780647 vga
* 4060742907 video
* 4060775547 s-video
*/
void setup() {
Serial.begin(115200);
irrecv.enableIRIn();
pinMode(WHEEL_REAR_RIGHT_R, OUTPUT);
pinMode(WHEEL_REAR_RIGHT_F, OUTPUT);
pinMode(WHEEL_REAR_LEFT_R, OUTPUT);
pinMode(WHEEL_REAR_LEFT_F, OUTPUT);
pinMode(WHEEL_FRONT_RIGHT_R, OUTPUT);
pinMode(WHEEL_FRONT_RIGHT_F, OUTPUT);
pinMode(WHEEL_FRONT_LEFT_R, OUTPUT);
pinMode(WHEEL_FRONT_LEFT_F, OUTPUT);
}
void stop(){
digitalWrite(WHEEL_REAR_RIGHT_R, HIGH);
digitalWrite(WHEEL_REAR_RIGHT_F, HIGH);
digitalWrite(WHEEL_REAR_LEFT_R, HIGH);
digitalWrite(WHEEL_REAR_LEFT_F, HIGH);
digitalWrite(WHEEL_FRONT_RIGHT_R, HIGH);
digitalWrite(WHEEL_FRONT_RIGHT_F, HIGH);
digitalWrite(WHEEL_FRONT_LEFT_R, HIGH);
digitalWrite(WHEEL_FRONT_LEFT_F, HIGH);
}
void forward(){
digitalWrite(WHEEL_REAR_RIGHT_F, LOW);
digitalWrite(WHEEL_REAR_LEFT_F, LOW);
digitalWrite(WHEEL_FRONT_RIGHT_F, LOW);
digitalWrite(WHEEL_FRONT_LEFT_F, LOW);
}
void backward(){
digitalWrite(WHEEL_REAR_RIGHT_R, LOW);
digitalWrite(WHEEL_REAR_LEFT_R, LOW);
digitalWrite(WHEEL_FRONT_RIGHT_R, LOW);
digitalWrite(WHEEL_FRONT_LEFT_R, LOW);
}
void strafe_l(){
digitalWrite(WHEEL_REAR_RIGHT_R, LOW);
digitalWrite(WHEEL_REAR_LEFT_F, LOW);
digitalWrite(WHEEL_FRONT_RIGHT_F, LOW);
digitalWrite(WHEEL_FRONT_LEFT_R, LOW);
}
void strafe_r(){
digitalWrite(WHEEL_REAR_RIGHT_F, LOW);
digitalWrite(WHEEL_REAR_LEFT_R, LOW);
digitalWrite(WHEEL_FRONT_RIGHT_R, LOW);
digitalWrite(WHEEL_FRONT_LEFT_F, LOW);
}
void diag_l_f(){
digitalWrite(WHEEL_REAR_LEFT_F, LOW);
digitalWrite(WHEEL_FRONT_RIGHT_F, LOW);
}
void diag_r_r(){
digitalWrite(WHEEL_REAR_LEFT_R, LOW);
digitalWrite(WHEEL_FRONT_RIGHT_R, LOW);
}
void diag_r_f(){
digitalWrite(WHEEL_REAR_RIGHT_F, LOW);
digitalWrite(WHEEL_FRONT_LEFT_F, LOW);
}
void diag_l_r(){
digitalWrite(WHEEL_REAR_RIGHT_R, LOW);
digitalWrite(WHEEL_FRONT_LEFT_R, LOW);
}
void turn_l(){
digitalWrite(WHEEL_REAR_RIGHT_R, LOW);
digitalWrite(WHEEL_REAR_LEFT_F, LOW);
digitalWrite(WHEEL_FRONT_RIGHT_R, LOW);
digitalWrite(WHEEL_FRONT_LEFT_F, LOW);
}
void turn_r(){
digitalWrite(WHEEL_REAR_RIGHT_F, LOW);
digitalWrite(WHEEL_REAR_LEFT_R, LOW);
digitalWrite(WHEEL_FRONT_RIGHT_F, LOW);
digitalWrite(WHEEL_FRONT_LEFT_R, LOW);
}
unsigned long getIRremote(){
static unsigned long lastValue = 0;
decode_results irResults;
if(irrecv.decode(&irResults) == 0){
return 0;
}
if(!(irResults.decode_type == NEC && irResults.value == REPEAT)){
lastValue = irResults.value;
}
irrecv.resume();
return lastValue;
}
void loop() {
unsigned long remote = getIRremote();
static unsigned long modus;
if(remote){
Serial.println(remote);
modus = remote;
}
if(modus == 4060792887){
forward();
}else if(modus == 4060801047){
stop();
}else if(modus == 4060752087){
backward();
}else if(modus == 4060768407){
strafe_l();
}else if(modus == 4060784727){
strafe_r();
}else if(modus == 4060750047){
turn_l();
}else if(modus == 4060790847){
turn_r();
}else if(modus == 4060786767){
diag_l_f();
}else if(modus == 4060778607){
diag_r_r();
}else if(modus == 4060782687){
diag_r_f();
}else if(modus == 4060766367){
diag_l_r();
}
/*
stop();
forward();
delay(1000);
stop();
backward();
delay(1000);
stop();
strafe_l();
delay(1000);
stop();
strafe_r();
delay(1000);
stop();
diag_l_f();
delay(1000);
stop();
diag_l_r();
delay(1000);
stop();
diag_r_f();
delay(1000);
stop();
diag_r_r();
delay(1000);
stop();
turn_l();
delay(1000);
stop();
turn_r();
delay(1000);
stop();
*/
}