init
This commit is contained in:
+107
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Arduino Wireless Communication Tutorial
|
||||
* Example 1 - Transmitter Code
|
||||
*
|
||||
* by Dejan Nedelkovski, www.HowToMechatronics.com
|
||||
*
|
||||
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
|
||||
*/
|
||||
/*
|
||||
Wirering for the Display:
|
||||
SSD1306 ESP8266/MCU ESP32 Arduino UNO Arduino Mega
|
||||
VCC 3.3V 3.3V 3.3V 3.3V
|
||||
GND GND GND GND GND
|
||||
SCL D1 / GPIO 5 GPIO 22 GPIO 9 GPIO 5
|
||||
SDA D2 / GPIO 4 GPIO 21 GPIO 10 GPIO 53
|
||||
*/
|
||||
|
||||
|
||||
#include "OledDisplay.h"
|
||||
#include "RadioController.h"
|
||||
|
||||
OledDisplay display;
|
||||
RadioController radio;
|
||||
|
||||
// joystick board
|
||||
int up_button = 2; // Boton Amarillo - A
|
||||
int down_button = 4; // Boton Amarillo - C
|
||||
int left_button = 5; // Boton Azul - D
|
||||
int right_button = 3; // Boton Azul - B
|
||||
int start_button = 6; // Boton F
|
||||
int select_button = 7; // Boton E
|
||||
int analog_button = 8; //
|
||||
int x_axis = A0;
|
||||
int y_axis = A1;
|
||||
int buttons[] = { up_button, down_button, left_button,
|
||||
right_button, start_button, select_button, analog_button };
|
||||
|
||||
#define PIN_POTI A3
|
||||
int val = 0;
|
||||
|
||||
unsigned long previousTime = 0; // Variable to store the previous time
|
||||
unsigned long interval = 3000;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// gamepad module
|
||||
for (int i; i < 7; i++) {
|
||||
pinMode(buttons[i], INPUT);
|
||||
digitalWrite(buttons[i], HIGH);
|
||||
}
|
||||
|
||||
radio.setup(9, 10);
|
||||
|
||||
display.setup();
|
||||
|
||||
Serial.println("Setup finished");
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// 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|";
|
||||
|
||||
previousTime = currentTime; // Update the previous time
|
||||
}
|
||||
|
||||
|
||||
if (digitalRead(left_button) == LOW) {
|
||||
msgToSend += "Stop|";
|
||||
} else if (digitalRead(up_button) == LOW) {
|
||||
msgToSend += "Up|";
|
||||
} else if (digitalRead(down_button) == LOW) {
|
||||
msgToSend += "Down|";
|
||||
}
|
||||
|
||||
// Serial.println(msgToSend);
|
||||
|
||||
radio.send(msgToSend);
|
||||
|
||||
//display_inputs();
|
||||
delay(10);
|
||||
}
|
||||
|
||||
void display_inputs() {
|
||||
int x = analogRead(x_axis);
|
||||
int y = analogRead(y_axis);
|
||||
Serial.println("X:" + String(x) + " | Y:" + String(y));
|
||||
}
|
||||
Reference in New Issue
Block a user