资料介绍
描述
介绍
制作气垫船后,我决定如果我想使用自制无人机(可能用于未来的项目),我需要一个遥控器。因此,我创建了自己的遥控器。
确实,我之前有一个控制器,但在这种情况下它几乎没用,因为驾驶无人机肯定需要更多信息,以避免潜在的碰撞。
所以,我决定制作这个全新的遥控器,由 TFT 屏幕、nRF24l01 无线电模块和 arduino mega 组成。
首先,我需要一个能够显示连接到它的 RC 设备信息的控制器:速度、电机推力、角度等……
然后,我想要适应每种情况的东西:这就是为什么我在这个控制器上制作了不同的模板,以确保遥控器至少有一个适用于每个设备的模板。特别是有5个模板(4个用于驾驶,1个用于技术特性)。
最后,在构思过程中,我添加了在这些模板之间导航的可能性,你得到它,一个完整的模块化遥控器!
该控制器发送一个名为“data”的 6 个 int 数组(data[0] 到 data[5])并接收一个名为“infos”的数组(infos[0] 到 infos[5])。
发送 :
接收 :
PS:这些信息默认在模板 A 上设置,因为它用于将在 Hackster.io 上发布的未来无人机,否则这些信息可以根据您的设备和需要在修改后的模板上显示(和更改)。
3D设计
遥控器看起来像一个游戏控制器,这是我设计它时的主要问题:它必须手感舒适。
此外,您可以在主面板上看到的孔用于拧紧 arduino mega 和屏幕支架。
连接
红点和绿点用于 TFT 屏幕(使用电线将它们连接到 TFT):它需要连接,因为当它们插在一起时可以看到它们已连接。
代码
这是代码:
#include
#include
#include
#include
#include
#include
#include
#include
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFA60
#define LIME 0x07FF
#define ORANGE1 ((255 / 8) << 11) | ((165 / 4) << 5) | (0 / 8)
#define ORANGE2 ((255 / 8) << 11) | ((187 / 4) << 5) | (61 / 8)
#define ORANGE3 ((255 / 8) << 11) | ((201 / 4) << 5) | (102 / 8)
#define BLUE1 ((2 / 8) << 11) | ((9 / 4) << 5) | (219 / 8)
#define BLUE2 ((36 / 8) << 11) | ((43 / 4) << 5) | (253 / 8)
#define BLUE3 ((103 / 8) << 11) | ((108 / 4) << 5) | (254 / 8)
#define DARKBLUE1 ((2 / 8) << 11) | ((8 / 4) << 5) | (185 / 8)
#define DARKBLUE2 ((1 / 8) << 11) | ((5 / 4) << 5) | (118 / 8)
#define RED1 ((255 / 8) << 11) | ((0 / 4) << 5) | (0 / 8)
#define RED2 ((255 / 8) << 11) | ((61 / 4) << 5) | (61 / 8)
#define RED3 ((255 / 8) << 11) | ((122 / 4) << 5) | (122 / 8)
#define CACTUS1 ((196 / 8) << 11) | ((235 / 4) << 5) | (20 / 8)
#define CACTUS2 ((217 / 8) << 11) | ((242 / 4) << 5) | (103 / 8)
#define CACTUS3 ((231 / 8) << 11) | ((247 / 4) << 5) | (158 / 8)
#define YELLOW1 ((235 / 8) << 11) | ((254 / 4) << 5) | (1 / 8)
#define YELLOW2 ((239 / 8) << 11) | ((254 / 4) << 5) | (62 / 8)
#define YELLOW3 ((244 / 8) << 11) | ((254 / 4) << 5) | (123 / 8)
#define MAGENTA1 ((245 / 8) << 11) | ((0 / 4) << 5) | (245 / 8)
#define MAGENTA2 ((255 / 8) << 11) | ((82 / 4) << 5) | (255 / 8)
#define MAGENTA3 ((255 / 8) << 11) | ((184 / 4) << 5) | (255 / 8)
#define CYAN1 ((0 / 8) << 11) | ((255 / 4) << 5) | (255 / 8)
#define CYAN2 ((122 / 8) << 11) | ((255 / 4) << 5) | (255 / 8)
#define CYAN3 ((204 / 8) << 11) | ((255 / 4) << 5) | (255 / 8)
#define PINK1 ((230 / 8) << 11) | ((7 / 4) << 5) | (92 / 8)
#define PINK2 ((249 / 8) << 11) | ((60 / 4) << 5) | (132 / 8)
#define PINK3 ((251 / 8) << 11) | ((131 / 4) << 5) | (177 / 8)
#define GREEN1 ((15 / 8) << 11) | ((186 / 4) << 5) | (15 / 8)
#define GREEN2 ((36 / 8) << 11) | ((238 / 4) << 5) | (36 / 8)
#define GREEN3 ((103 / 8) << 11) | ((243 / 4) << 5) | (103 / 8)
#define GREY1 ((128 / 8) << 11) | ((128 / 4) << 5) | (128 / 8)
#define GREY2 ((168 / 8) << 11) | ((168 / 4) << 5) | (168 / 8)
#define GREY3 ((200 / 8) << 11) | ((200 / 4) << 5) | (200 / 8)
#define PURPLE1 ((92 / 8) << 11) | ((0 / 4) << 5) | (92 / 8)
#define PURPLE2 ((133 / 8) << 11) | ((0 / 4) << 5) | (133 / 8)
#define PURPLE3 ((173 / 8) << 11) | ((0 / 4) << 5) | (173 / 8)
#define BROWN1 ((41 / 8) << 11) | ((10 / 4) << 5) | (10 / 8)
#define BROWN2 ((73 / 8) << 11) | ((19 / 4) << 5) | (19 / 8)
#define BROWN3 ((106 / 8) << 11) | ((27 / 4) << 5) | (27 / 8)
#define BROWN4 ((138 / 8) << 11) | ((35 / 4) << 5) | (35 / 8)
#define BROWN5 ((171 / 8) << 11) | ((43 / 4) << 5) | (43 / 8)
#define BROWN6 ((203 / 8) << 11) | ((52 / 4) << 5) | (52 / 8)
#define BROWN7 ((212 / 8) << 11) | ((84 / 4) << 5) | (84 / 8)
#define BEIGE1 ((221 / 8) << 11) | ((221 / 4) << 5) | (136 / 8)
#define BEIGE2 ((230 / 8) << 11) | ((230 / 4) << 5) | (168 / 8)
#define BEIGE3 ((235 / 8) << 11) | ((235 / 4) << 5) | (184 / 8)
#define YP A2
#define XM A3
#define YM 8
#define XP 9
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 400);
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TSPoint p;
int data[6];
int infos[6];
int xjoy1;
int yjoy1;
int xjoy2;
int yjoy2;
float angley1 = 0;
float angley2 = 0;
int menu = 0;
int startingmenuvariable = 0;
int menulaunch = 0;
int timer = 0;
int delaybutton4;
int delaybutton5;
void setup(){
Serial.begin(9600);
tft.reset();
tft.begin(0x9341);
tft.fillScreen(BLACK);
tft.setRotation(3);
Mirf.cePin = 10;
Mirf.csnPin = 11;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.channel = 1;
Mirf.payload = sizeof(int) * 6;
Mirf.config();
Mirf.setTADDR((byte *) "nrf02");
Mirf.setRADDR((byte *) "nrf01");
data[4] = 0;
data[5] = 0;
}
void menuAstatis(){
tft.fillCircle(40, 0, 100, MAGENTA);
tft.fillCircle(280, 0, 25, YELLOW);
tft.fillRect(21, 21, 79, 80, BLACK);
tft.fillRect(121, 21, 79, 80, BLACK);
tft.drawCircle(65, 170, 40, WHITE);
tft.drawCircle(175, 170, 40, WHITE);
tft.fillRect(10, 110, 200, 30, BLACK);
tft.fillRect(10, 200, 200, 40, BLACK);
tft.fillCircle(100, 240, 30, CYAN);
tft.drawRect(20, 20, 80, 81, WHITE);
tft.drawRect(120, 20, 80, 81, WHITE);
tft.setCursor(220, 35);
tft.setTextColor(RED);
tft.setTextSize(1);
tft.println("PWM5 :");
tft.setCursor(220, 55);
tft.println("PWM6 :");
tft.setCursor(220, 75);
tft.println("PWM9 :");
tft.setCursor(215, 95);
tft.println("PWM10 :");
tft.setTextColor(GREEN3);
tft.setCursor(45, 150);
tft.println("Angle X");
tft.setCursor(155, 150);
tft.println("Angle Y");
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
void menuA(){
if(infos[0]>179){
infos[0] = 179;
}
if(infos[1]>179){
infos[1] = 179;
}
if(infos[2]>179){
infos[2] = 179;
}
if(infos[3]>179){
infos[3] = 179;
}
tft.fillCircle(xjoy1, yjoy1, 2, BLACK);
tft.fillCircle(xjoy2, yjoy2, 2, BLACK);
tft.fillRect(54, 170, 20, 10, BLACK);
tft.fillRect(164, 170, 20, 10, BLACK);
tft.fillRect(259, 34, 24, 71, BLACK);
xjoy1 = map(data[1], 0, 1024, 31, 89);
yjoy1 = map(data[0], 1024, 0, 31, 89);
tft.fillCircle(xjoy1, yjoy1, 2, BLUE);
xjoy2 = map(data[3], 0, 1024, 131, 189);
yjoy2 = map(data[2], 1024, 0, 31, 89);
tft.fillCircle(xjoy2, yjoy2, 2, BLUE);
tft.setTextColor(GREEN1);
tft.setCursor(60, 170);
tft.println(infos[4]);
tft.setCursor(170, 170);
tft.println(infos[5]);
tft.setCursor(260, 35);
tft.setTextColor(RED);
tft.setTextSize(1);
tft.println(infos[0]);
tft.setCursor(260, 55);
tft.println(infos[1]);
tft.setCursor(260, 75);
tft.println(infos[2]);
tft.setCursor(260, 95);
tft.println(infos[3]);
}
void menuBstatis(){
tft.fillCircle(50, 0, 80, PINK1);
tft.fillCircle(240, 20, 130, ORANGE);
tft.fillRect(31, 31, 114, 115, BLACK);
tft.fillRect(176, 31, 114, 115, BLACK);
tft.drawRect(30, 30, 115, 116, WHITE);
tft.drawRect(175, 30, 115, 116, WHITE);
tft.setCursor(40, 160);
tft.setTextColor(CYAN);
tft.setTextSize(1);
tft.println("X:");
tft.setCursor(40, 175);
tft.println("Y:");
tft.setCursor(160, 160);
tft.println("X:");
tft.setCursor(160, 175);
tft.println("Y:");
tft.fillRoundRect(39, 199, 62, 32, 3, WHITE);
tft.fillRoundRect(139, 199, 62, 32, 3, WHITE);
if(data[4]==1){
tft.fillRoundRect(41, 201, 58, 28, 3, GREEN);
}
else{
tft.fillRoundRect(41, 201, 58, 28, 3, RED);
}
if(data[5]==1){
tft.fillRoundRect(141, 201, 58, 28, 3, GREEN);
}
else{
tft.fillRoundRect(141, 201, 58, 28, 3, RED);
}
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
void menuB(){
tft.drawCircle(xjoy2, yjoy2, 4, BLACK);
tft.drawCircle(xjoy1, yjoy1, 4, BLACK);
tft.fillRect(54, 159, 26, 25, BLACK);
tft.fillRect(174, 159, 26, 25, BLACK);
xjoy1 = map(data[1], 0, 1024, 41, 134);
yjoy1 = map(data[0], 1024, 0, 41, 134);
tft.drawCircle(xjoy1, yjoy1, 4, BLUE);
xjoy2 = map(data[3], 0, 1024, 186, 279);
yjoy2 = map(data[2], 1024, 0, 41, 134);
tft.drawCircle(xjoy2, yjoy2, 4, BLUE);
tft.setCursor(55, 160);
tft.setTextColor(CYAN);
tft.setTextSize(1);
tft.println(data[1]);
tft.setCursor(55, 175);
tft.println(data[0]);
tft.setCursor(175, 160);
tft.println(data[3]);
tft.setCursor(175, 175);
tft.println(data[2]);
if(timer<=100){
timer++;
}
if(p.z > ts.pressureThreshhold){
if(p.x>700 && p.y<300 && data[4]==1 && timer>=5){
data[4] = 0;
tft.fillRoundRect(41, 201, 58, 28, 3, RED);
timer = 0;
}else{}
if(p.x>700 && p.y<300 && data[4]==0 && timer>=5){
data[4] = 1;
tft.fillRoundRect(41, 201, 58, 28, 3, GREEN);
timer = 0;
}else{}
if(p.x<700 && p.y<300 && data[5]==1 && timer>=5){
data[5] = 0;
tft.fillRoundRect(141, 201, 58, 28, 3, RED);
timer = 0;
}else{}
if(p.x<700 && p.y<300 && data[5]==0 && timer>=5){
data[5] = 1;
tft.fillRoundRect(141, 201, 58, 28, 3, GREEN);
timer = 0;
}else{}
}
}
void menuCstatis(){
tft.setCursor(10, 20);
tft.setTextColor(RED);
tft.setTextSize(1);
tft.println("This template must be created on the code.");
tft.setCursor(10, 40);
tft.println("For more informations, check up :");
tft.setCursor(10, 60);
tft.println("Hackster.io /https://www.hackster.io/MisterBotBreak");
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
void menuC(){
}
void menuDstatis(){
tft.setCursor(10, 20);
tft.setTextColor(RED);
tft.setTextSize(1);
tft.println("This template must be created through the code.");
tft.setCursor(10, 40);
tft.println("For more informations, check up :");
tft.setCursor(10, 60);
tft.println("Hackster.io /https://www.hackster.io/MisterBotBreak");
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
void menuD(){
}
void menuCharactsstatis(){
tft.fillScreen(BLACK);
tft.fillCircle(320, 0, 150, BLUE);
tft.fillCircle(0, 160, 80, GREEN);
tft.fillCircle(140, 240, 50, RED);
tft.setCursor(60, 20);
tft.setTextColor(CYAN);
tft.setTextSize(1);
tft.println("Remote Controller Characteristics");
tft.setCursor(10, 50);
tft.setTextColor(WHITE);
tft.println("This controller transmits data using a");
tft.setCursor(245, 50);
tft.setTextColor(RED);
tft.println("nRF24l01");
tft.setCursor(10, 65);
tft.setTextColor(RED);
tft.println("radio module.");
tft.setCursor(10, 90);
tft.setTextColor(WHITE);
tft.println("Packet sent : data, array (6 * int) ");
tft.setCursor(10, 105);
tft.println("Packet received : infos, array (6 * int) ");
tft.setCursor(10, 125);
tft.println("By default, infos[0,1,2,3] are associated with PWMs");
tft.setCursor(10, 140);
tft.println("while infos[4,5] are angles (gyroscope).");
tft.setCursor(10, 155);
tft.println("Template A is especially for drone driving.");
tft.setCursor(10, 175);
tft.println("CE : D10");
tft.setCursor(10, 190);
tft.println("CSN : D11");
tft.setCursor(100, 175);
tft.println("MOSI : D51");
tft.setCursor(100, 190);
tft.println("MISO : D50");
tft.setCursor(10, 205);
tft.println("SCK : D52");
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
void menuCharacts(){
}
void menuXstatis(){
//put all static elements of your patern here
}
void menuX(){
//put all dynamic elements of your patern here
}
void startingmenustatis(){
tft.drawRoundRect(20, 60, 130, 40, 3, WHITE);
tft.drawRoundRect(170, 60, 130, 40, 3, WHITE);
tft.drawRoundRect(20, 120, 130, 40, 3, WHITE);
tft.drawRoundRect(170, 120, 130, 40, 3, WHITE);
tft.drawRoundRect(20, 180, 205, 40, 3, WHITE);
tft.setCursor(18, 20);
tft.setTextColor(CYAN);
tft.setTextSize(1);
tft.println("Choose your template for this remote controler !");
tft.setCursor(51, 67);
tft.setTextColor(RED);
tft.println("Template A");
tft.setCursor(53, 85);
tft.println("(standart)");
tft.setCursor(203, 75);
tft.setTextColor(ORANGE);
tft.println("Template B");
tft.setCursor(51, 135);
tft.setTextColor(YELLOW);
tft.println("Template C");
tft.setCursor(203, 135);
tft.setTextColor(GREEN);
tft.println("Template D");
tft.setCursor(51, 195);
tft.setTextColor(MAGENTA);
tft.println("Technical Characteristics");
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
void loop(){
data[0] = analogRead(A8);
data[1] = analogRead(A9);
data[2] = analogRead(A10);
data[3] = analogRead(A11);
digitalWrite(13, HIGH);
p = ts.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if(startingmenuvariable==0 && menu==0){
startingmenustatis();
startingmenuvariable = 1;
}
if(menu > 0 && p.x < 350 && p.y < 500){
tft.fillScreen(BLACK);
startingmenustatis();
menu = 0;
menulaunch = 0;
}
if(p.z > ts.pressureThreshhold){
if(menu==0 || menulaunch==0){
if(p.y>550 && p.x>600){
menu = 1;
}
if(p.y>550 && p.x<600){
menu = 2;
}
if(550>p.y && p.y>340 && p.x>600){
menu = 3;
}
if(550>p.y && p.y>340 && p.x<600){
menu = 4;
}
if(p.y<340 && p.x>400){
menu = 5;
}
}
}
Serial.println(data[4]);
if(menu==1 && menulaunch != 1){
tft.fillScreen(BLACK);
menuAstatis();
menulaunch = 1;
}
if(menu==1){
menuA();
}
if(menu==2 && menulaunch != 2){
tft.fillScreen(BLACK);
menuBstatis();
menulaunch = 2;
}
if(menu==2){
menuB();
}
if(menu==3 && menulaunch != 3){
tft.fillScreen(BLACK);
menuCstatis();
menulaunch = 3;
}
if(menu==3){
menuC();
}
if(menu==4 && menulaunch != 4){
tft.fillScreen(BLACK);
menuDstatis();
menulaunch = 4;
}
if(menu==4){
menuD();
}
if(menu==5 && menulaunch != 5){
tft.fillScreen(BLACK);
menuCharactsstatis();
menulaunch = 5;
}
if(menu==5){
menuCharacts();
}
/*PROGRAM YOUR OWN PATERN HERE : X = the patern' letter / x = the patern' number
if(menu==x && menulaunch != x){
tft.fillScreen(BLACK);
menuBstatis();
menulaunch = x;
}
if(menu==x){
menuX();
}
*/
data[0] = analogRead(A8);
data[1] = analogRead(A9);
data[2] = analogRead(A10);
data[3] = analogRead(A11);
if(Mirf.dataReady()){
Mirf.getData((byte *) &infos);
Serial.println(infos[0]);
Serial.println(infos[1]);
Serial.println(infos[2]);
Serial.println(infos[3]);
Serial.println(infos[4]);
Serial.println(infos[5]);
}
delay(10);
Mirf.send((byte *) &data);
while(Mirf.isSending());
}
它可以分为多个部分。首先,我们设置所有使用 TFT(颜色、引脚等)和用于模板导航(“menu”、“menulaunch”等)、无线电通信(“data[6]”、“ infos[6]") 和其他触觉变量(“timer”、“delaybutton4”等):
#include
#include
#include
#include
#include
#include
#include
#include
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFA60
#define LIME 0x07FF
#define ORANGE1 ((255 / 8) << 11) | ((165 / 4) << 5) | (0 / 8)
#define ORANGE2 ((255 / 8) << 11) | ((187 / 4) << 5) | (61 / 8)
#define ORANGE3 ((255 / 8) << 11) | ((201 / 4) << 5) | (102 / 8)
#define BLUE1 ((2 / 8) << 11) | ((9 / 4) << 5) | (219 / 8)
#define BLUE2 ((36 / 8) << 11) | ((43 / 4) << 5) | (253 / 8)
#define BLUE3 ((103 / 8) << 11) | ((108 / 4) << 5) | (254 / 8)
#define DARKBLUE1 ((2 / 8) << 11) | ((8 / 4) << 5) | (185 / 8)
#define DARKBLUE2 ((1 / 8) << 11) | ((5 / 4) << 5) | (118 / 8)
#define RED1 ((255 / 8) << 11) | ((0 / 4) << 5) | (0 / 8)
#define RED2 ((255 / 8) << 11) | ((61 / 4) << 5) | (61 / 8)
#define RED3 ((255 / 8) << 11) | ((122 / 4) << 5) | (122 / 8)
#define CACTUS1 ((196 / 8) << 11) | ((235 / 4) << 5) | (20 / 8)
#define CACTUS2 ((217 / 8) << 11) | ((242 / 4) << 5) | (103 / 8)
#define CACTUS3 ((231 / 8) << 11) | ((247 / 4) << 5) | (158 / 8)
#define YELLOW1 ((235 / 8) << 11) | ((254 / 4) << 5) | (1 / 8)
#define YELLOW2 ((239 / 8) << 11) | ((254 / 4) << 5) | (62 / 8)
#define YELLOW3 ((244 / 8) << 11) | ((254 / 4) << 5) | (123 / 8)
#define MAGENTA1 ((245 / 8) << 11) | ((0 / 4) << 5) | (245 / 8)
#define MAGENTA2 ((255 / 8) << 11) | ((82 / 4) << 5) | (255 / 8)
#define MAGENTA3 ((255 / 8) << 11) | ((184 / 4) << 5) | (255 / 8)
#define CYAN1 ((0 / 8) << 11) | ((255 / 4) << 5) | (255 / 8)
#define CYAN2 ((122 / 8) << 11) | ((255 / 4) << 5) | (255 / 8)
#define CYAN3 ((204 / 8) << 11) | ((255 / 4) << 5) | (255 / 8)
#define PINK1 ((230 / 8) << 11) | ((7 / 4) << 5) | (92 / 8)
#define PINK2 ((249 / 8) << 11) | ((60 / 4) << 5) | (132 / 8)
#define PINK3 ((251 / 8) << 11) | ((131 / 4) << 5) | (177 / 8)
#define GREEN1 ((15 / 8) << 11) | ((186 / 4) << 5) | (15 / 8)
#define GREEN2 ((36 / 8) << 11) | ((238 / 4) << 5) | (36 / 8)
#define GREEN3 ((103 / 8) << 11) | ((243 / 4) << 5) | (103 / 8)
#define GREY1 ((128 / 8) << 11) | ((128 / 4) << 5) | (128 / 8)
#define GREY2 ((168 / 8) << 11) | ((168 / 4) << 5) | (168 / 8)
#define GREY3 ((200 / 8) << 11) | ((200 / 4) << 5) | (200 / 8)
#define PURPLE1 ((92 / 8) << 11) | ((0 / 4) << 5) | (92 / 8)
#define PURPLE2 ((133 / 8) << 11) | ((0 / 4) << 5) | (133 / 8)
#define PURPLE3 ((173 / 8) << 11) | ((0 / 4) << 5) | (173 / 8)
#define BROWN1 ((41 / 8) << 11) | ((10 / 4) << 5) | (10 / 8)
#define BROWN2 ((73 / 8) << 11) | ((19 / 4) << 5) | (19 / 8)
#define BROWN3 ((106 / 8) << 11) | ((27 / 4) << 5) | (27 / 8)
#define BROWN4 ((138 / 8) << 11) | ((35 / 4) << 5) | (35 / 8)
#define BROWN5 ((171 / 8) << 11) | ((43 / 4) << 5) | (43 / 8)
#define BROWN6 ((203 / 8) << 11) | ((52 / 4) << 5) | (52 / 8)
#define BROWN7 ((212 / 8) << 11) | ((84 / 4) << 5) | (84 / 8)
#define BEIGE1 ((221 / 8) << 11) | ((221 / 4) << 5) | (136 / 8)
#define BEIGE2 ((230 / 8) << 11) | ((230 / 4) << 5) | (168 / 8)
#define BEIGE3 ((235 / 8) << 11) | ((235 / 4) << 5) | (184 / 8)
#define YP A2
#define XM A3
#define YM 8
#define XP 9
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 400);
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TSPoint p;
int data[6];
int infos[6];
int xjoy1;
int yjoy1;
int xjoy2;
int yjoy2;
float angley1 = 0;
float angley2 = 0;
int menu = 0;
int startingmenuvariable = 0;
int menulaunch = 0;
int timer = 0;
int delaybutton4;
int delaybutton5;
然后,我们通过定义参数(通道、地址、旋转、有效负载等)来初始化 nRF24l01 和 TFT 屏幕:
void setup(){
Serial.begin(9600);
tft.reset();
tft.begin(0x9341);
tft.fillScreen(BLACK);
tft.setRotation(3);
Mirf.cePin = 10;
Mirf.csnPin = 11;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.channel = 1;
Mirf.payload = sizeof(int) * 6;
Mirf.config();
Mirf.setTADDR((byte *) "nrf02");
Mirf.setRADDR((byte *) "nrf01");
data[4] = 0;
data[5] = 0;
}
之后,我们必须设置与模板相关的功能。对于一个模板,我们必须有 2 个函数:一个用于设置静态元素,这将完成一次(会有动态元素,所以我们需要将所有静态元素放在一个特定的函数上,该函数只会使用一次,它的为了避免延迟和不必要的闪烁),另一个用于将重复的动态元素(作为循环功能)以允许动态元素移动。我们还将使用所有模板为菜单定义一个特定功能:
void menuAstatis(){
tft.fillCircle(40, 0, 100, MAGENTA);
tft.fillCircle(280, 0, 25, YELLOW);
tft.fillRect(21, 21, 79, 80, BLACK);
tft.fillRect(121, 21, 79, 80, BLACK);
tft.drawCircle(65, 170, 40, WHITE);
tft.drawCircle(175, 170, 40, WHITE);
tft.fillRect(10, 110, 200, 30, BLACK);
tft.fillRect(10, 200, 200, 40, BLACK);
tft.fillCircle(100, 240, 30, CYAN);
tft.drawRect(20, 20, 80, 81, WHITE);
tft.drawRect(120, 20, 80, 81, WHITE);
tft.setCursor(220, 35);
tft.setTextColor(RED);
tft.setTextSize(1);
tft.println("PWM5 :");
tft.setCursor(220, 55);
tft.println("PWM6 :");
tft.setCursor(220, 75);
tft.println("PWM9 :");
tft.setCursor(215, 95);
tft.println("PWM10 :");
tft.setTextColor(GREEN3);
tft.setCursor(45, 150);
tft.println("Angle X");
tft.setCursor(155, 150);
tft.println("Angle Y");
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
void menuA(){
if(infos[0]>179){
infos[0] = 179;
}
if(infos[1]>179){
infos[1] = 179;
}
if(infos[2]>179){
infos[2] = 179;
}
if(infos[3]>179){
infos[3] = 179;
}
tft.fillCircle(xjoy1, yjoy1, 2, BLACK);
tft.fillCircle(xjoy2, yjoy2, 2, BLACK);
tft.fillRect(54, 170, 20, 10, BLACK);
tft.fillRect(164, 170, 20, 10, BLACK);
tft.fillRect(259, 34, 24, 71, BLACK);
xjoy1 = map(data[1], 0, 1024, 31, 89);
yjoy1 = map(data[0], 1024, 0, 31, 89);
tft.fillCircle(xjoy1, yjoy1, 2, BLUE);
xjoy2 = map(data[3], 0, 1024, 131, 189);
yjoy2 = map(data[2], 1024, 0, 31, 89);
tft.fillCircle(xjoy2, yjoy2, 2, BLUE);
tft.setTextColor(GREEN1);
tft.setCursor(60, 170);
tft.println(infos[4]);
tft.setCursor(170, 170);
tft.println(infos[5]);
tft.setCursor(260, 35);
tft.setTextColor(RED);
tft.setTextSize(1);
tft.println(infos[0]);
tft.setCursor(260, 55);
tft.println(infos[1]);
tft.setCursor(260, 75);
tft.println(infos[2]);
tft.setCursor(260, 95);
tft.println(infos[3]);
}
void menuBstatis(){
tft.fillCircle(50, 0, 80, PINK1);
tft.fillCircle(240, 20, 130, ORANGE);
tft.fillRect(31, 31, 114, 115, BLACK);
tft.fillRect(176, 31, 114, 115, BLACK);
tft.drawRect(30, 30, 115, 116, WHITE);
tft.drawRect(175, 30, 115, 116, WHITE);
tft.setCursor(40, 160);
tft.setTextColor(CYAN);
tft.setTextSize(1);
tft.println("X:");
tft.setCursor(40, 175);
tft.println("Y:");
tft.setCursor(160, 160);
tft.println("X:");
tft.setCursor(160, 175);
tft.println("Y:");
tft.fillRoundRect(39, 199, 62, 32, 3, WHITE);
tft.fillRoundRect(139, 199, 62, 32, 3, WHITE);
if(data[4]==1){
tft.fillRoundRect(41, 201, 58, 28, 3, GREEN);
}
else{
tft.fillRoundRect(41, 201, 58, 28, 3, RED);
}
if(data[5]==1){
tft.fillRoundRect(141, 201, 58, 28, 3, GREEN);
}
else{
tft.fillRoundRect(141, 201, 58, 28, 3, RED);
}
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
void menuB(){
tft.drawCircle(xjoy2, yjoy2, 4, BLACK);
tft.drawCircle(xjoy1, yjoy1, 4, BLACK);
tft.fillRect(54, 159, 26, 25, BLACK);
tft.fillRect(174, 159, 26, 25, BLACK);
xjoy1 = map(data[1], 0, 1024, 41, 134);
yjoy1 = map(data[0], 1024, 0, 41, 134);
tft.drawCircle(xjoy1, yjoy1, 4, BLUE);
xjoy2 = map(data[3], 0, 1024, 186, 279);
yjoy2 = map(data[2], 1024, 0, 41, 134);
tft.drawCircle(xjoy2, yjoy2, 4, BLUE);
tft.setCursor(55, 160);
tft.setTextColor(CYAN);
tft.setTextSize(1);
tft.println(data[1]);
tft.setCursor(55, 175);
tft.println(data[0]);
tft.setCursor(175, 160);
tft.println(data[3]);
tft.setCursor(175, 175);
tft.println(data[2]);
if(timer<=100){
timer++;
}
if(p.z > ts.pressureThreshhold){
if(p.x>700 && p.y<300 && data[4]==1 && timer>=5){
data[4] = 0;
tft.fillRoundRect(41, 201, 58, 28, 3, RED);
timer = 0;
}else{}
if(p.x>700 && p.y<300 && data[4]==0 && timer>=5){
data[4] = 1;
tft.fillRoundRect(41, 201, 58, 28, 3, GREEN);
timer = 0;
}else{}
if(p.x<700 && p.y<300 && data[5]==1 && timer>=5){
data[5] = 0;
tft.fillRoundRect(141, 201, 58, 28, 3, RED);
timer = 0;
}else{}
if(p.x<700 && p.y<300 && data[5]==0 && timer>=5){
data[5] = 1;
tft.fillRoundRect(141, 201, 58, 28, 3, GREEN);
timer = 0;
}else{}
}
}
void menuCstatis(){
tft.setCursor(10, 20);
tft.setTextColor(RED);
tft.setTextSize(1);
tft.println("This template must be created on the code.");
tft.setCursor(10, 40);
tft.println("For more informations, check up :");
tft.setCursor(10, 60);
tft.println("Hackster.io /https://www.hackster.io/MisterBotBreak");
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
void menuC(){
}
void menuDstatis(){
tft.setCursor(10, 20);
tft.setTextColor(RED);
tft.setTextSize(1);
tft.println("This template must be created through the code.");
tft.setCursor(10, 40);
tft.println("For more informations, check up :");
tft.setCursor(10, 60);
tft.println("Hackster.io /https://www.hackster.io/MisterBotBreak");
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
void menuD(){
}
void menuCharactsstatis(){
tft.fillScreen(BLACK);
tft.fillCircle(320, 0, 150, BLUE);
tft.fillCircle(0, 160, 80, GREEN);
tft.fillCircle(140, 240, 50, RED);
tft.setCursor(60, 20);
tft.setTextColor(CYAN);
tft.setTextSize(1);
tft.println("Remote Controller Characteristics");
tft.setCursor(10, 50);
tft.setTextColor(WHITE);
tft.println("This controller transmits data using a");
tft.setCursor(245, 50);
tft.setTextColor(RED);
tft.println("nRF24l01");
tft.setCursor(10, 65);
tft.setTextColor(RED);
tft.println("radio module.");
tft.setCursor(10, 90);
tft.setTextColor(WHITE);
tft.println("Packet sent : data, array (6 * int) ");
tft.setCursor(10, 105);
tft.println("Packet received : infos, array (6 * int) ");
tft.setCursor(10, 125);
tft.println("By default, infos[0,1,2,3] are associated with PWMs");
tft.setCursor(10, 140);
tft.println("while infos[4,5] are angles (gyroscope).");
tft.setCursor(10, 155);
tft.println("Template A is especially for drone driving.");
tft.setCursor(10, 175);
tft.println("CE : D10");
tft.setCursor(10, 190);
tft.println("CSN : D11");
tft.setCursor(100, 175);
tft.println("MOSI : D51");
tft.setCursor(100, 190);
tft.println("MISO : D50");
tft.setCursor(10, 205);
tft.println("SCK : D52");
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
void menuCharacts(){
}
void menuXstatis(){
//put all static elements of your patern here
}
void menuX(){
//put all dynamic elements of your patern here
}
void startingmenustatis(){
tft.drawRoundRect(20, 60, 130, 40, 3, WHITE);
tft.drawRoundRect(170, 60, 130, 40, 3, WHITE);
tft.drawRoundRect(20, 120, 130, 40, 3, WHITE);
tft.drawRoundRect(170, 120, 130, 40, 3, WHITE);
tft.drawRoundRect(20, 180, 205, 40, 3, WHITE);
tft.setCursor(18, 20);
tft.setTextColor(CYAN);
tft.setTextSize(1);
tft.println("Choose your template for this remote controler !");
tft.setCursor(51, 67);
tft.setTextColor(RED);
tft.println("Template A");
tft.setCursor(53, 85);
tft.println("(standart)");
tft.setCursor(203, 75);
tft.setTextColor(ORANGE);
tft.println("Template B");
tft.setCursor(51, 135);
tft.setTextColor(YELLOW);
tft.println("Template C");
tft.setCursor(203, 135);
tft.setTextColor(GREEN);
tft.println("Template D");
tft.setCursor(51, 195);
tft.setTextColor(MAGENTA);
tft.println("Technical Characteristics");
tft.fillRoundRect(245, 180, 55, 40, 3, RED);
tft.fillRoundRect(248, 183, 49, 34, 3, BLACK);
tft.setTextSize(1);
tft.setCursor(263, 195);
tft.setTextColor(CYAN);
tft.println("Back ");
}
最后,
我们收集所有模拟信息。此外,我们启动 TFT 的可触性并更改三个不同的模板选择变量:“menu” = 我们在哪个模板中,“menulaunch” = 0 或 1、2、3、4、5、6 = 如果我们已经启动静态元素(1 到 6)或不启动(0),基本上,如果"menu" = X
和"menulaunch" =! X
,这意味着我们已经按下另一个模板的按钮,因此我们设置“menuXstatis”(静态元素)然后“menuX” (动态元素,在循环中)。然后我们发送无线电连接的所有信息(“Mirf.getData”,“Mirf.isSending”):
void loop(){
data[0] = analogRead(A8);
data[1] = analogRead(A9);
data[2] = analogRead(A10);
data[3] = analogRead(A11);
digitalWrite(13, HIGH);
p = ts.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if(startingmenuvariable==0 && menu==0){
startingmenustatis();
startingmenuvariable = 1;
}
if(menu > 0 && p.x < 350 && p.y < 500){
tft.fillScreen(BLACK);
startingmenustatis();
menu = 0;
menulaunch = 0;
}
if(p.z > ts.pressureThreshhold){
if(menu==0 || menulaunch==0){
if(p.y>550 && p.x>600){
menu = 1;
}
if(p.y>550 && p.x<600){
menu = 2;
}
if(550>p.y && p.y>340 && p.x>600){
menu = 3;
}
if(550>p.y && p.y>340 && p.x<600){
menu = 4;
}
if(p.y<340 && p.x>400){
menu = 5;
}
}
}
Serial.println(data[4]);
if(menu==1 && menulaunch != 1){
tft.fillScreen(BLACK);
menuAstatis();
menulaunch = 1;
}
if(menu==1){
menuA();
}
if(menu==2 && menulaunch != 2){
tft.fillScreen(BLACK);
menuBstatis();
menulaunch = 2;
}
if(menu==2){
menuB();
}
if(menu==3 && menulaunch != 3){
tft.fillScreen(BLACK);
menuCstatis();
menulaunch = 3;
}
if(menu==3){
menuC();
}
if(menu==4 && menulaunch != 4){
tft.fillScreen(BLACK);
menuDstatis();
menulaunch = 4;
}
if(menu==4){
menuD();
}
if(menu==5 && menulaunch != 5){
tft.fillScreen(BLACK);
menuCharactsstatis();
menulaunch = 5;
}
if(menu==5){
menuCharacts();
}
/*PROGRAM YOUR OWN PATERN HERE : X = the patern' letter / x = the patern' number
if(menu==x && menulaunch != x){
tft.fillScreen(BLACK);
menuBstatis();
menulaunch = x;
}
if(menu==x){
menuX();
}
*/
data[0] = analogRead(A8);
data[1] = analogRead(A9);
data[2] = analogRead(A10);
data[3] = analogRead(A11);
if(Mirf.dataReady()){
Mirf.getData((byte *) &infos);
Serial.println(infos[0]);
Serial.println(infos[1]);
Serial.println(infos[2]);
Serial.println(infos[3]);
Serial.println(infos[4]);
Serial.println(infos[5]);
}
delay(10);
Mirf.send((byte *) &data);
while(Mirf.isSending());
}
在 Tipeee 上关注我以获取有关即将开展的项目的更多信息:D!
- 高职组“电子产品设计及制作”卷一:智能机器人控制器设计及制作 0次下载
- 制作智能房间控制器
- RC控制器开源分享
- 利用单片机制作红外线测温控制器
- 基于DSP的高压训线机器人数字化控制器 10次下载
- EPSON RC+ 7.0用于开发机器人控制器的应用软件使用手册免费下载 37次下载
- 液位控制器设计与制作解析 19次下载
- 电梯控制器设计与制作 18次下载
- 基于RC700/RC90机器人控制器PG动作系统设计应用 19次下载
- 灯光控制集成电路与灯光控制器制作 0次下载
- RC500制作读卡器的全套电路及PCB板图.rar
- 家电自动控制器的制作及电路图
- 电风扇加装阵风控制器电路及制作
- 电磁水阀自动控制器电路及制作
- 水箱自动上水控制器电路及制作
- PID控制器与PWM控制器的区别 1656次阅读
- PID控制器与开关控制器的区别 398次阅读
- 制作一个Ethersweep步进电机控制器 670次阅读
- PID控制器概述与制作实例 5313次阅读
- 低端微控制器单元中RC振荡器的校准机制 1947次阅读
- 如何使用Arduino Leonardo和MPU6050制作一个有线的手势控制器 2625次阅读
- 用单运放制作的控制器电路 3070次阅读
- 如何制作简易降压控制器 2379次阅读
- dfrobotuHex微型低功耗控制器简介 1407次阅读
- 电话远程控制器的设计与制作 2187次阅读
- LCD驱动分析_LCD控制器设置及代码详解 1.8w次阅读
- 什么是运动控制器_运动控制器的工作原理及应用 3.6w次阅读
- led灯带控制器怎么用 2.8w次阅读
- 自制红外线自动门控制器电路制作方案 4414次阅读
- 用MAX6641制作的智能温度控制器电路图 4262次阅读
下载排行
本周
- 1PC1013三合一快充数据线充电芯片介绍
- 1.03 MB | 7次下载 | 免费
- 2PCB板EMC/EMI的设计技巧
- 0.20 MB | 3次下载 | 免费
- 32024PMIC市场洞察
- 2.23 MB | 2次下载 | 免费
- 4MCF8315EVM评估模块
- 2.09MB | 1次下载 | 免费
- 5ADI高性能电源管理解决方案
- 2.43 MB | 1次下载 | 免费
- 6UC3842工作原理及开关电源电路
- 0.08 MB | 1次下载 | 免费
- 7JFG-AS02微量程扭矩传感器数据表
- 0.32 MB | 1次下载 | 免费
- 8JFG-3D02三维力传感器数据表
- 0.58 MB | 1次下载 | 免费
本月
- 1XL4015+LM358恒压恒流电路图
- 0.38 MB | 147次下载 | 1 积分
- 2新概念模拟电路第四册信号处理电路电子书免费下载
- 10.69 MB | 65次下载 | 免费
- 3PCB布线和布局电路设计规则
- 0.40 MB | 29次下载 | 免费
- 4智能门锁原理图
- 0.39 MB | 12次下载 | 免费
- 5GB/T4706.1-2024 家用和类似用途电器的安全第1部分:通用要求
- 7.43 MB | 11次下载 | 1 积分
- 6JESD79-5C_v1.30-2024 内存技术规范
- 2.71 MB | 10次下载 | 免费
- 7elmo直线电机驱动调试细则
- 4.76 MB | 9次下载 | 6 积分
- 8PC1013三合一快充数据线充电芯片介绍
- 1.03 MB | 7次下载 | 免费
总榜
- 1matlab软件下载入口
- 未知 | 935115次下载 | 10 积分
- 2开源硬件-PMP21529.1-4 开关降压/升压双向直流/直流转换器 PCB layout 设计
- 1.48MB | 420061次下载 | 10 积分
- 3Altium DXP2002下载入口
- 未知 | 233084次下载 | 10 积分
- 4电路仿真软件multisim 10.0免费下载
- 340992 | 191367次下载 | 10 积分
- 5十天学会AVR单片机与C语言视频教程 下载
- 158M | 183330次下载 | 10 积分
- 6labview8.5下载
- 未知 | 81581次下载 | 10 积分
- 7Keil工具MDK-Arm免费下载
- 0.02 MB | 73806次下载 | 10 积分
- 8LabVIEW 8.6下载
- 未知 | 65985次下载 | 10 积分
评论
查看更多