Jetzt mit Structs

Nur y und immernoch lienear und 3V
This commit is contained in:
DenialOfIntelligence 2023-06-01 16:36:40 +02:00
parent 7eca1fd819
commit e1b90f9a71
2 changed files with 19 additions and 49 deletions

View file

@ -26,16 +26,17 @@ void setup() {
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(A5, OUTPUT);
}
void loop() {
struct dataStruct {
int Xposition;
int Yposition;
} myData;
if (radio.available()) {
Serial.println("aaa");
char text[2] = {0};
radio.read(&text, sizeof(text) - 1);
String code = String(text); // Array -> Zeichen ("code")
if (code == "w") {
radio.read( &myData, sizeof(myData) );
if (myData.Yposition >= 500) {
digitalWrite(3, 1);
digitalWrite(2, 0);
digitalWrite(4, 0);
@ -46,7 +47,7 @@ void loop() {
digitalWrite(A5, 1);
}
if (code == "s") {
if (myData.Yposition <= 100) {
digitalWrite(2, 1);
digitalWrite(3, 0);
digitalWrite(5, 0);
@ -56,27 +57,9 @@ void loop() {
digitalWrite(A5, 0);
digitalWrite(A4, 1);
}
Serial.println(code);
if (code == "d") {
digitalWrite(2, 0);
digitalWrite(3, 1);
digitalWrite(4, 0);
digitalWrite(5, 1);
}
if (code == "a") {
digitalWrite(2, 1);
digitalWrite(3, 0);
digitalWrite(4, 1);
digitalWrite(5, 0);
}
}
else {
delay(30);
if (!radio.available()) {
if (myData.Yposition>100 && myData.Y-position<500) {
digitalWrite(2, 0);
digitalWrite(3, 0);
digitalWrite(4, 0);
@ -89,3 +72,4 @@ void loop() {
}
delay(10);
}
}

View file

@ -2,7 +2,6 @@
#include <RF24.h>
//TODO Sende analoge daten für joystick
RF24 radio(9, 10); // (CE, CSN)
char text[0]="";
const byte address[6] = "1RF24";
void setup() {
@ -12,32 +11,19 @@ void setup() {
radio.openWritingPipe(address);
radio.stopListening();
// Serial.begin(9600);
}
void loop() {
// Serial.println(radio.isChipConnected());
struct dataStruct {
int Xposition;
int Yposition;
if (analogRead(1)>500){
char text[]="w";
radio.write(&text, sizeof(text));
}
if (analogRead(1)<100){
char text[]="s";
radio.write(&text, sizeof(text));
}
else{
if(analogRead(0)>500){
char text[]="d";
radio.write(&text, sizeof(text));
}
if (analogRead(0)<100){
char text[]="a";
radio.write(&text, sizeof(text));
}
} myData;
myData.Xposition = analogRead(0);
myData.Yposition = analogRead(1);
radio.write(&myData, sizeof(myData), 1);
delay(10);
}
}