Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Tutorial von
- http://mertarduinotutorial.blogspot.de/2017/04/arduino-remote-controlled-tank-with.html
- ---- Receiver Code ----
- Mert Arduino Tutorial & Projects (YouTube)
- Please Subscribe for Support
- */
- #include <Servo.h> //die Bibliothek, die uns hilft, den Servomotor zu steuern
- #include <SPI.h> //die Kommunikationsschnittstelle mit dem Modem
- #include "RF24.h" //die Bibliothek, mit der wir das Funkmodem steuern können (nRF24L)
- //define our L298N control pins
- //Motor A
- const int RightMotorForward = 2; // IN1
- const int RightMotorBackward = 3; // IN2
- //Motor B
- const int LeftMotorForward = 4; // IN3
- const int LeftMotorBackward = 6; // IN4
- //Definieren Sie den Servonamen
- Servo myServo;
- RF24 radio(5,10); /*Dieses Objekt stellt ein Modem dar, das mit dem Arduino verbunden ist.
- Die Argumente 5 und 10 sind digitale Pin-Nummern, an die sich Signale anschließen
- CE und CSN sind verbunden.*/
- const uint64_t pipe = 0xE8E8F0F0E1LL; //die Adresse des Modems, das Daten vom Arduino empfängt.
- int data[1];
- void setup(){
- pinMode(RightMotorForward, OUTPUT);
- pinMode(LeftMotorForward, OUTPUT);
- pinMode(LeftMotorBackward, OUTPUT);
- pinMode(RightMotorBackward, OUTPUT);
- //Definieren Sie die Servo-Eingangspins
- myServo.attach(14); //A0
- radio.begin(); //Es aktiviert das Modem.
- radio.openReadingPipe(1, pipe); //bestimmt die Adresse Ihres Modems, die Daten empfängt.
- radio.startListening(); //Aktivieren Sie den Empfang von Daten über Modem
- }
- void loop(){
- if(radio.available()){
- radio.read(data, 1);
- if(data[0] < 11 && data[0] > 6){
- // Das ist rückwärts
- // Stellen Sie einen Motor A rückwärts ein
- digitalWrite(RightMotorForward, LOW);
- digitalWrite(RightMotorBackward, HIGH);
- // Stellen Sie einen Motor B rückwärts ein
- digitalWrite(LeftMotorForward, LOW);
- digitalWrite(LeftMotorBackward, HIGH);
- }
- if(data[0] > -1 && data[0] < 4){
- // Das ist vorwärts
- // Setze einen Motor A vorwärts
- digitalWrite(RightMotorForward, HIGH);
- digitalWrite(RightMotorBackward, LOW);
- // Setze einen Motor B vorwärts
- digitalWrite(LeftMotorForward, HIGH);
- digitalWrite(LeftMotorBackward, LOW);
- }
- if (data[0] == 5){
- // Stopp Motoren
- digitalWrite(RightMotorForward, LOW);
- digitalWrite(RightMotorBackward, LOW);
- digitalWrite(LeftMotorForward, LOW);
- digitalWrite(LeftMotorBackward, LOW);
- }
- // Das ist Rückwärts
- // Setze einen Motor A rückwärts
- if(data[0] < 21 && data[0] > 16){
- digitalWrite(RightMotorForward, HIGH);
- digitalWrite(RightMotorBackward, LOW);
- // Setze einen Motor A rückwärts
- digitalWrite(LeftMotorForward, LOW);
- digitalWrite(LeftMotorBackward, HIGH);
- }
- // Biegen Sie rechts ab
- if(data[0] > 10 && data[0] < 14){
- digitalWrite(RightMotorForward, LOW);
- digitalWrite(RightMotorBackward, HIGH);
- digitalWrite(LeftMotorForward, HIGH);
- digitalWrite(LeftMotorBackward, LOW);
- }
- // Biegen Sie links ab
- if(data[0] == 15){
- digitalWrite(RightMotorForward, LOW);
- digitalWrite(RightMotorBackward, LOW);
- digitalWrite(LeftMotorForward, LOW);
- digitalWrite(LeftMotorBackward, LOW);
- }
- // für den Servomotor
- if(data[0] < 31 && data[0] > 21){
- int potValue = data[0];
- int potPos = map(potValue, 21, 30, 10, 170);
- myServo.write(potPos);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement