資料介紹
描述
介紹
制作氣墊船后,我決定如果我想使用自制無人機(jī)(可能用于未來的項(xiàng)目),我需要一個(gè)遙控器。因此,我創(chuàng)建了自己的遙控器。
確實(shí),我之前有一個(gè)控制器,但在這種情況下它幾乎沒用,因?yàn)轳{駛無人機(jī)肯定需要更多信息,以避免潛在的碰撞。
所以,我決定制作這個(gè)全新的遙控器,由 TFT 屏幕、nRF24l01 無線電模塊和 arduino mega 組成。
首先,我需要一個(gè)能夠顯示連接到它的 RC 設(shè)備信息的控制器:速度、電機(jī)推力、角度等……
然后,我想要適應(yīng)每種情況的東西:這就是為什么我在這個(gè)控制器上制作了不同的模板,以確保遙控器至少有一個(gè)適用于每個(gè)設(shè)備的模板。特別是有5個(gè)模板(4個(gè)用于駕駛,1個(gè)用于技術(shù)特性)。
最后,在構(gòu)思過程中,我添加了在這些模板之間導(dǎo)航的可能性,你得到它,一個(gè)完整的模塊化遙控器!
該控制器發(fā)送一個(gè)名為“data”的 6 個(gè) int 數(shù)組(data[0] 到 data[5])并接收一個(gè)名為“infos”的數(shù)組(infos[0] 到 infos[5])。
發(fā)送 :
接收 :
PS:這些信息默認(rèn)在模板 A 上設(shè)置,因?yàn)樗糜趯⒃?Hackster.io 上發(fā)布的未來無人機(jī),否則這些信息可以根據(jù)您的設(shè)備和需要在修改后的模板上顯示(和更改)。
3D設(shè)計(jì)
遙控器看起來像一個(gè)游戲控制器,這是我設(shè)計(jì)它時(shí)的主要問題:它必須手感舒適。
此外,您可以在主面板上看到的孔用于擰緊 arduino mega 和屏幕支架。
連接
紅點(diǎn)和綠點(diǎn)用于 TFT 屏幕(使用電線將它們連接到 TFT):它需要連接,因?yàn)楫?dāng)它們插在一起時(shí)可以看到它們已連接。
代碼
這是代碼:
#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());
}
它可以分為多個(gè)部分。首先,我們?cè)O(shè)置所有使用 TFT(顏色、引腳等)和用于模板導(dǎo)航(“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;
然后,我們通過定義參數(shù)(通道、地址、旋轉(zhuǎn)、有效負(fù)載等)來初始化 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;
}
之后,我們必須設(shè)置與模板相關(guān)的功能。對(duì)于一個(gè)模板,我們必須有 2 個(gè)函數(shù):一個(gè)用于設(shè)置靜態(tài)元素,這將完成一次(會(huì)有動(dòng)態(tài)元素,所以我們需要將所有靜態(tài)元素放在一個(gè)特定的函數(shù)上,該函數(shù)只會(huì)使用一次,它的為了避免延遲和不必要的閃爍),另一個(gè)用于將重復(fù)的動(dòng)態(tài)元素(作為循環(huán)功能)以允許動(dòng)態(tài)元素移動(dòng)。我們還將使用所有模板為菜單定義一個(gè)特定功能:
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 ");
}
最后,
我們收集所有模擬信息。此外,我們啟動(dòng) TFT 的可觸性并更改三個(gè)不同的模板選擇變量:“menu” = 我們?cè)谀膫€(gè)模板中,“menulaunch” = 0 或 1、2、3、4、5、6 = 如果我們已經(jīng)啟動(dòng)靜態(tài)元素(1 到 6)或不啟動(dòng)(0),基本上,如果"menu" = X
和"menulaunch" =! X
,這意味著我們已經(jīng)按下另一個(gè)模板的按鈕,因此我們?cè)O(shè)置“menuXstatis”(靜態(tài)元素)然后“menuX” (動(dòng)態(tài)元素,在循環(huán)中)。然后我們發(fā)送無線電連接的所有信息(“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 上關(guān)注我以獲取有關(guān)即將開展的項(xiàng)目的更多信息:D!
- 高職組“電子產(chǎn)品設(shè)計(jì)及制作”卷一:智能機(jī)器人控制器設(shè)計(jì)及制作 0次下載
- 制作智能房間控制器
- RC控制器開源分享
- 利用單片機(jī)制作紅外線測溫控制器
- 基于DSP的高壓訓(xùn)線機(jī)器人數(shù)字化控制器 10次下載
- EPSON RC+ 7.0用于開發(fā)機(jī)器人控制器的應(yīng)用軟件使用手冊(cè)免費(fèi)下載 37次下載
- 液位控制器設(shè)計(jì)與制作解析 19次下載
- 電梯控制器設(shè)計(jì)與制作 18次下載
- 基于RC700/RC90機(jī)器人控制器PG動(dòng)作系統(tǒng)設(shè)計(jì)應(yīng)用 19次下載
- 燈光控制集成電路與燈光控制器制作 0次下載
- RC500制作讀卡器的全套電路及PCB板圖.rar
- 家電自動(dòng)控制器的制作及電路圖
- 電風(fēng)扇加裝陣風(fēng)控制器電路及制作
- 電磁水閥自動(dòng)控制器電路及制作
- 水箱自動(dòng)上水控制器電路及制作
- PID控制器與PWM控制器的區(qū)別 1656次閱讀
- PID控制器與開關(guān)控制器的區(qū)別 398次閱讀
- 制作一個(gè)Ethersweep步進(jìn)電機(jī)控制器 670次閱讀
- PID控制器概述與制作實(shí)例 5313次閱讀
- 低端微控制器單元中RC振蕩器的校準(zhǔn)機(jī)制 1947次閱讀
- 如何使用Arduino Leonardo和MPU6050制作一個(gè)有線的手勢控制器 2625次閱讀
- 用單運(yùn)放制作的控制器電路 3070次閱讀
- 如何制作簡易降壓控制器 2379次閱讀
- dfrobotuHex微型低功耗控制器簡介 1407次閱讀
- 電話遠(yuǎn)程控制器的設(shè)計(jì)與制作 2187次閱讀
- LCD驅(qū)動(dòng)分析_LCD控制器設(shè)置及代碼詳解 1.8w次閱讀
- 什么是運(yùn)動(dòng)控制器_運(yùn)動(dòng)控制器的工作原理及應(yīng)用 3.6w次閱讀
- led燈帶控制器怎么用 2.8w次閱讀
- 自制紅外線自動(dòng)門控制器電路制作方案 4414次閱讀
- 用MAX6641制作的智能溫度控制器電路圖 4262次閱讀
下載排行
本周
- 1山景DSP芯片AP8248A2數(shù)據(jù)手冊(cè)
- 1.06 MB | 532次下載 | 免費(fèi)
- 2RK3399完整板原理圖(支持平板,盒子VR)
- 3.28 MB | 339次下載 | 免費(fèi)
- 3TC358743XBG評(píng)估板參考手冊(cè)
- 1.36 MB | 330次下載 | 免費(fèi)
- 4DFM軟件使用教程
- 0.84 MB | 295次下載 | 免費(fèi)
- 5元宇宙深度解析—未來的未來-風(fēng)口還是泡沫
- 6.40 MB | 227次下載 | 免費(fèi)
- 6迪文DGUS開發(fā)指南
- 31.67 MB | 194次下載 | 免費(fèi)
- 7元宇宙底層硬件系列報(bào)告
- 13.42 MB | 182次下載 | 免費(fèi)
- 8FP5207XR-G1中文應(yīng)用手冊(cè)
- 1.09 MB | 178次下載 | 免費(fèi)
本月
- 1OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費(fèi)
- 2555集成電路應(yīng)用800例(新編版)
- 0.00 MB | 33566次下載 | 免費(fèi)
- 3接口電路圖大全
- 未知 | 30323次下載 | 免費(fèi)
- 4開關(guān)電源設(shè)計(jì)實(shí)例指南
- 未知 | 21549次下載 | 免費(fèi)
- 5電氣工程師手冊(cè)免費(fèi)下載(新編第二版pdf電子書)
- 0.00 MB | 15349次下載 | 免費(fèi)
- 6數(shù)字電路基礎(chǔ)pdf(下載)
- 未知 | 13750次下載 | 免費(fèi)
- 7電子制作實(shí)例集錦 下載
- 未知 | 8113次下載 | 免費(fèi)
- 8《LED驅(qū)動(dòng)電路設(shè)計(jì)》 溫德爾著
- 0.00 MB | 6656次下載 | 免費(fèi)
總榜
- 1matlab軟件下載入口
- 未知 | 935054次下載 | 免費(fèi)
- 2protel99se軟件下載(可英文版轉(zhuǎn)中文版)
- 78.1 MB | 537798次下載 | 免費(fèi)
- 3MATLAB 7.1 下載 (含軟件介紹)
- 未知 | 420027次下載 | 免費(fèi)
- 4OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費(fèi)
- 5Altium DXP2002下載入口
- 未知 | 233046次下載 | 免費(fèi)
- 6電路仿真軟件multisim 10.0免費(fèi)下載
- 340992 | 191187次下載 | 免費(fèi)
- 7十天學(xué)會(huì)AVR單片機(jī)與C語言視頻教程 下載
- 158M | 183279次下載 | 免費(fèi)
- 8proe5.0野火版下載(中文版免費(fèi)下載)
- 未知 | 138040次下載 | 免費(fèi)
評(píng)論
查看更多