精品国产人成在线_亚洲高清无码在线观看_国产在线视频国产永久2021_国产AV综合第一页一个的一区免费影院黑人_最近中文字幕MV高清在线视频

電子發燒友App

硬聲App

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示
電子發燒友網>電子資料下載>電子資料>如何制作RC控制器

如何制作RC控制器

2022-10-18 | zip | 0.33 MB | 次下載 | 免費

資料介紹

描述

介紹

制作氣墊船后,我決定如果我想使用自制無人機(可能用于未來的項目),我需要一個遙控器。因此,我創建了自己的遙控器。

確實,我之前有一個控制器,但在這種情況下它幾乎沒用,因為駕駛無人機肯定需要更多信息,以避免潛在的碰撞。

所以,我決定制作這個全新的遙控器,由 TFT 屏幕、nRF24l01 無線電模塊和 arduino mega 組成。

首先,我需要一個能夠顯示連接到它的 RC 設備信息的控制器:速度、電機推力、角度等……

然后,我想要適應每種情況的東西:這就是為什么我在這個控制器上制作了不同的模板,以確保遙控器至少有一個適用于每個設備的模板。特別是有5個模板(4個用于駕駛,1個用于技術特性)。

最后,在構思過程中,我添加了在這些模板之間導航的可能性,你得到它,一個完整的模塊化遙控器!

該控制器發送一個名為“data”的 6 個 int 數組(data[0] 到 data[5])并接收一個名為“infos”的數組(infos[0] 到 infos[5])。

發送 :

  • data[0], data[1], data[2], data[3] : 操縱桿模擬
  • data[4], data[5] : 按鈕(可以在模板 B 上激活)

接收

  • infos[0]、infos[1]、infos[2]、infos[3]:PWM(來自 4 個無刷電機
  • infos[4], infos[5] : 角度(來自陀螺儀

PS:這些信息默認在模板 A 上設置,因為它用于將在 Hackster.io 上發布的未來無人機,否則這些信息可以根據您的設備和需要在修改后的模板上顯示(和更改)。

img_20211219_182138_rXEhrwcK1U.jpg?auto=compress%2Cformat&w=740&h=555&fit=max
?
img_20211219_182108_xpdSwEuBiD.jpg?auto=compress%2Cformat&w=740&h=555&fit=max
?
img_20211219_182224_PJURBtf2ja.jpg?auto=compress%2Cformat&w=740&h=555&fit=max
?

3D設計

image_XJ9Vsgn748.png?auto=compress%2Cformat&w=740&h=555&fit=max
?
capture_decran_(1185)_YETcUrUW8B.png?auto=compress%2Cformat&w=740&h=555&fit=max
?
image_oKRpiufbP5.png?auto=compress%2Cformat&w=740&h=555&fit=max
(以確保屏幕不會脫離對主體 RC 的支撐)
?
image_8AzlPK3vGU.png?auto=compress%2Cformat&w=740&h=555&fit=max
(修復微控制器:Arduino Mega 和 nrf24l01)
?
capture_decran_(1185)_yetcuruw8b_li_8GymuPM2Hs.jpg?auto=compress%2Cformat&w=740&h=555&fit=max
紅色圓圈:TFT 屏幕支持,藍色圓圈:Arduino Mega 支持,粉色圓圈:操縱桿
?

遙控器看起來像一個游戲控制器,這是我設計它時的主要問題:它必須手感舒適。

此外,您可以在主面板上看到的孔用于擰緊 arduino mega 和屏幕支架。

連接

image_YVWKf20bW8.png?auto=compress%2Cformat&w=740&h=555&fit=max
?

紅點和綠點用于 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!

MisterBotBreak – Tipeee


下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評論

查看更多

下載排行

本周

  1. 1山景DSP芯片AP8248A2數據手冊
  2. 1.06 MB  |  532次下載  |  免費
  3. 2RK3399完整板原理圖(支持平板,盒子VR)
  4. 3.28 MB  |  339次下載  |  免費
  5. 3TC358743XBG評估板參考手冊
  6. 1.36 MB  |  330次下載  |  免費
  7. 4DFM軟件使用教程
  8. 0.84 MB  |  295次下載  |  免費
  9. 5元宇宙深度解析—未來的未來-風口還是泡沫
  10. 6.40 MB  |  227次下載  |  免費
  11. 6迪文DGUS開發指南
  12. 31.67 MB  |  194次下載  |  免費
  13. 7元宇宙底層硬件系列報告
  14. 13.42 MB  |  182次下載  |  免費
  15. 8FP5207XR-G1中文應用手冊
  16. 1.09 MB  |  178次下載  |  免費

本月

  1. 1OrCAD10.5下載OrCAD10.5中文版軟件
  2. 0.00 MB  |  234315次下載  |  免費
  3. 2555集成電路應用800例(新編版)
  4. 0.00 MB  |  33566次下載  |  免費
  5. 3接口電路圖大全
  6. 未知  |  30323次下載  |  免費
  7. 4開關電源設計實例指南
  8. 未知  |  21549次下載  |  免費
  9. 5電氣工程師手冊免費下載(新編第二版pdf電子書)
  10. 0.00 MB  |  15349次下載  |  免費
  11. 6數字電路基礎pdf(下載)
  12. 未知  |  13750次下載  |  免費
  13. 7電子制作實例集錦 下載
  14. 未知  |  8113次下載  |  免費
  15. 8《LED驅動電路設計》 溫德爾著
  16. 0.00 MB  |  6656次下載  |  免費

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935054次下載  |  免費
  3. 2protel99se軟件下載(可英文版轉中文版)
  4. 78.1 MB  |  537798次下載  |  免費
  5. 3MATLAB 7.1 下載 (含軟件介紹)
  6. 未知  |  420027次下載  |  免費
  7. 4OrCAD10.5下載OrCAD10.5中文版軟件
  8. 0.00 MB  |  234315次下載  |  免費
  9. 5Altium DXP2002下載入口
  10. 未知  |  233046次下載  |  免費
  11. 6電路仿真軟件multisim 10.0免費下載
  12. 340992  |  191187次下載  |  免費
  13. 7十天學會AVR單片機與C語言視頻教程 下載
  14. 158M  |  183279次下載  |  免費
  15. 8proe5.0野火版下載(中文版免費下載)
  16. 未知  |  138040次下載  |  免費