Projekt:Tüftlerclub/Boot
Erscheinungsbild
Boote
[Bearbeiten]Fotos
[Bearbeiten]ToDo
[Bearbeiten]- Steuerung: Ruder über Servomotor
- Schwimmkörper abdichten
- Antrieb?
Boot
[Bearbeiten]nRF24L01-Sender
[Bearbeiten]#include <SPI.h>
#include <RF24.h>
RF24 radio(9, 10); // (CE, CSN)
char text[0]="";
const byte address[6] = "4RF24";
void setup() {
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(120);
radio.openWritingPipe(address);
radio.stopListening();
// Serial.begin(9600);
}
void loop() {
// Serial.println(radio.isChipConnected());
if (analogRead(1)>700){
char text[]="w";
radio.write(&text, sizeof(text));
}
if (analogRead(1)<100){
char text[]="s";
radio.write(&text, sizeof(text));
}
else{
if(analogRead(0)>700){
char text[]="d";
radio.write(&text, sizeof(text));
}
if (analogRead(0)<100){
char text[]="a";
radio.write(&text, sizeof(text));
}
delay(10);
}
}
Empfänger
[Bearbeiten]#include <SPI.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(7, 8); // (CE, CSN)
Servo servoA;
Servo servoB;
const byte address[6] = "4RF24";
void setup() {
// Serial.begin(115200);
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(120);
radio.openReadingPipe(0,address);
radio.startListening();
pinMode(2,OUTPUT);
pinMode(4,OUTPUT);
servoA.attach(3);
servoB.attach(5);
servoA.write(90);
servoB.write(90);
}
void loop() {
// Serial.println(code);
if(radio.available()){
char text[2] = {0};
radio.read(&text, sizeof(text)-1);
String code = String(text); // Array -> Zeichen ("code")
if (code == "w") {
digitalWrite(2,0);
digitalWrite(4,1);
}
if (code == "s"){
digitalWrite(2,1);
digitalWrite(4,0);
}
if (code=="d"){
servoA.write(50);
servoB.write(50);
delay(500);
}
if (code=="a"){
servoA.write(130);
servoB.write(130);
delay(500);
}
}
else {
delay(30);
if (!radio.available()){
digitalWrite(2,0);
digitalWrite(4,0);
servoA.write(90);
servoB.write(90);
}}
delay(10);
}