Projekt:Tüftlerclub/Infrarotfahrzeug
Erscheinungsbild
Infrarotfahrzeug
[Bearbeiten]Steuerung
[Bearbeiten]Antrieb mit Mecanum-Rädern
[Bearbeiten]Notizbuch
[Bearbeiten]Infrarotsteuerung für Mecanum-Antrieb
[Bearbeiten]#include <IRremote.h>
// 1 = 69;
// 2 = 70;
// 3 = 71;
// 4 = 68;
// 5 = 64;
// 6 = 67;
// 7 = 7;
// 8 = 21;
// 9 = 9;
// 0 = 25;
// Asterisk = 22;
// Rhombus = 13;
// OK = 28;
// Up = 24;
// Down = 82;
// Left = 8;
// Right = 90;
int IrWert = 0;
const int IrPin = 11;
int pins[] = {2,3,4,5,6,7,8,9};
int vorwaerts[] = {0,1,0,1,0,1,0,1};
int rueckwaerts[] = {1,0,1,0,1,0,1,0};
int rechts[] = {1,0,0,1,1,0,0,1};
int links[] = {0,1,1,0,0,1,1,0};
int stopp[] = {0,0,0,0,0,0,0,0};
int rr[] = {0,1,0,1,1,0,1,0};
int rl[] = {1,0,1,0,0,1,0,1};
void setup() {
IrReceiver.begin(IrPin);
for (int i = 0; i < 8 ; i++) {
pinMode(pins[i],OUTPUT);
}
for (int i = 0; i < 8 ; i++) {
digitalWrite(pins[i],LOW);
}
}
void loop() {
if (IrReceiver.decode()) {
IrReceiver.resume();
IrWert = IrReceiver.decodedIRData.command;
if (IrWert == 24) {
for (int i = 0; i < 8 ; i++) {
digitalWrite(pins[i],vorwaerts[i]);
}
delay(200);
for (int i = 0; i < 8 ; i++){
digitalWrite(pins[i],stopp[i]);
}
}
if (IrWert == 82) {
for (int i = 0; i < 8 ; i++) {
digitalWrite(pins[i],rueckwaerts [i]);
}
delay(200);
for (int i = 0; i < 8 ; i++){
digitalWrite(pins[i],stopp[i]);
}
}
if (IrWert == 8) {
for (int i = 0; i < 8 ; i++) {
digitalWrite(pins[i],rechts [i]);
}
delay(200);
for (int i = 0; i < 8 ; i++){
digitalWrite(pins[i],stopp[i]);
}
}
if (IrWert == 90) {
for (int i = 0; i < 8 ; i++) {
digitalWrite(pins[i],links [i]);
}
delay(200);
for (int i = 0; i < 8 ; i++){
digitalWrite(pins[i],stopp[i]);
}
}
if (IrWert == 68) {
for (int i = 0; i < 8 ; i++) {
digitalWrite(pins[i],rr [i]);
}
delay(200);
for (int i = 0; i < 8 ; i++){
digitalWrite(pins[i],stopp[i]);
}
}
if (IrWert == 67) {
for (int i = 0; i < 8 ; i++) {
digitalWrite(pins[i],rl [i]);
}
delay(200);
for (int i = 0; i < 8 ; i++){
digitalWrite(pins[i],stopp[i]);
}
}
}
}
Steuerung für Motor Shield
[Bearbeiten]#include <IRremote.h>
// 1 = 69;
// 2 = 70;
// 3 = 71;
// 4 = 68;
// 5 = 64;
// 6 = 67;
// 7 = 7;
// 8 = 21;
// 9 = 9;
// 0 = 25;
// Asterisk = 22;
// Rhombus = 13;
// OK = 28;
// Up = 24;
// Down = 82;
// Left = 8;
// Right = 90;
int IrWert = 0;
const int IrPin = 10;
const int MotorA = 12;
const int TempoA = 3;
const int BremseA = 9;
const int MotorB = 13;
const int TempoB = 11;
const int BremseB = 8;
const int rechts = HIGH;
const int links = LOW;
void setup() {
IrReceiver.begin(IrPin);
pinMode(MotorA, OUTPUT);
pinMode(TempoA, OUTPUT);
pinMode(BremseA, OUTPUT);
pinMode(MotorB, OUTPUT);
pinMode(TempoB, OUTPUT);
pinMode(BremseB, OUTPUT);
}
void loop() {
if (IrReceiver.decode()) {
IrReceiver.resume();
IrWert = IrReceiver.decodedIRData.command;
if (IrWert == 24) {
digitalWrite(MotorA, rechts);
digitalWrite(MotorB, rechts);
analogWrite(TempoA, 255);
analogWrite(TempoB, 255);
delay(200);
analogWrite(TempoA, 0);
analogWrite(TempoB, 0);
}
if (IrWert == 82) {
digitalWrite(MotorA, links);
digitalWrite(MotorB, links);
analogWrite(TempoA, 255);
analogWrite(TempoB, 255);
delay(200);
analogWrite(TempoA, 0);
analogWrite(TempoB, 0);
}
if (IrWert == 8) {
digitalWrite(MotorA, links);
digitalWrite(MotorB, rechts);
analogWrite(TempoA, 255);
analogWrite(TempoB, 255);
delay(200);
analogWrite(TempoA, 0);
analogWrite(TempoB, 0);
}
if (IrWert == 90) {
digitalWrite(MotorA, rechts);
digitalWrite(MotorB, links);
analogWrite(TempoA, 255);
analogWrite(TempoB, 255);
delay(200);
analogWrite(TempoA, 0);
analogWrite(TempoB, 0);
}
else {
}
}
}