working version 1

This commit is contained in:
cally22
2023-07-08 22:44:00 +02:00
parent d1816ba485
commit 6cc938d45b
3 changed files with 105 additions and 59 deletions
+38 -20
View File
@@ -39,7 +39,7 @@ int buttons[] = { up_button, down_button, left_button,
int val = 0;
unsigned long previousTime = 0; // Variable to store the previous time
unsigned long interval = 3000;
unsigned long interval = 1000;
void setup() {
Serial.begin(115200);
@@ -55,49 +55,67 @@ void setup() {
display.setup();
Serial.println("Setup finished");
delay(2000);
display.clear();
}
void loop() {
char msgToSend[32] = "";
// val = map(analogRead(PIN_POTI), 0, 676, 30, 110);
// Serial.println(val);
// String msg = radio.receive();
// Serial.println(msg);
// display.droneMessage("PT:0.00|RL:0.00|MP_LF:1000");
// display.droneMessage(msg);
delay(50);
String msgToSend = "";
unsigned long currentTime = millis(); // Get the current time
if (currentTime - previousTime >= interval) {
// Perform your action here
// This code will execute every 3 seconds
msgToSend += "Alive|";
strcat(msgToSend, "Alive|");
previousTime = currentTime; // Update the previous time
}
if (digitalRead(left_button) == LOW) {
msgToSend += "Stop|";
strcat(msgToSend, "Stop|");
} else if (digitalRead(up_button) == LOW) {
msgToSend += "Up|";
strcat(msgToSend, "Up|");
} else if (digitalRead(down_button) == LOW) {
msgToSend += "Down|";
strcat(msgToSend, "Down|");
} else if (digitalRead(right_button) == LOW) {
strcat(msgToSend, "MOTOR|");
}
if (strlen(msgToSend) != 0) {
display.writeLine(msgToSend, 5);
// display.showDroneMessage();
}
// Serial.print("Send:");
// Serial.println(msgToSend);
int tx = 0;
const char* recText = radio.sendAck(msgToSend, tx);
// Serial.println(recText);
radio.send(msgToSend);
const char* transmitMsg = "RIP";
if (tx == 1) {
transmitMsg = "TX";
}
display.writeLine(transmitMsg, 6);
//display_inputs();
delay(10);
if (strncmp(recText, "Alive", 5) == 0) {
display.writeLine(recText, 0);
}else if (strncmp(recText, "BL", 2) == 0) {
display.writeLine(recText, 1);
}else if (strncmp(recText, "BR", 2) == 0) {
display.writeLine(recText, 2);
}else if (strncmp(recText, "FL", 2) == 0) {
display.writeLine(recText, 3);
}else if (strncmp(recText, "FR", 2) == 0) {
display.writeLine(recText, 4);
}
// display_inputs();
delay(50);
}
void display_inputs() {