×

如何制作RC控制器

消耗积分:0 | 格式:zip | 大小:0.33 MB | 2022-10-18

韩刚龙

分享资料个

描述

介绍

制作气垫船后,我决定如果我想使用自制无人机(可能用于未来的项目),我需要一个遥控器。因此,我创建了自己的遥控器。

确实,我之前有一个控制器,但在这种情况下它几乎没用,因为驾驶无人机肯定需要更多信息,以避免潜在的碰撞。

所以,我决定制作这个全新的遥控器,由 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


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !

'+ '

'+ '

'+ ''+ '
'+ ''+ ''+ '
'+ ''+ '' ); $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code ==5){ $(pop_this).attr('href',"/login/index.html"); return false } if(data.code == 2){ //跳转到VIP升级页面 window.location.href="//m.obk20.com/vip/index?aid=" + webid return false } //是会员 if (data.code > 0) { $('body').append(htmlSetNormalDownload); var getWidth=$("#poplayer").width(); $("#poplayer").css("margin-left","-"+getWidth/2+"px"); $('#tips').html(data.msg) $('.download_confirm').click(function(){ $('#dialog').remove(); }) } else { var down_url = $('#vipdownload').attr('data-url'); isBindAnalysisForm(pop_this, down_url, 1) } }); }); //是否开通VIP $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code == 2 || data.code ==5){ //跳转到VIP升级页面 $('#vipdownload>span').text("开通VIP 免费下载") return false }else{ // 待续费 if(data.code == 3) { vipExpiredInfo.ifVipExpired = true vipExpiredInfo.vipExpiredDate = data.data.endoftime } $('#vipdownload .icon-vip-tips').remove() $('#vipdownload>span').text("VIP免积分下载") } }); }).on("click",".download_cancel",function(){ $('#dialog').remove(); }) var setWeixinShare={};//定义默认的微信分享信息,页面如果要自定义分享,直接更改此变量即可 if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){ var d={ title:'如何制作RC控制器',//标题 desc:$('[name=description]').attr("content"), //描述 imgUrl:'https://'+location.host+'/static/images/ele-logo.png',// 分享图标,默认是logo link:'',//链接 type:'',// 分享类型,music、video或link,不填默认为link dataUrl:'',//如果type是music或video,则要提供数据链接,默认为空 success:'', // 用户确认分享后执行的回调函数 cancel:''// 用户取消分享后执行的回调函数 } setWeixinShare=$.extend(d,setWeixinShare); $.ajax({ url:"//www.obk20.com/app/wechat/index.php?s=Home/ShareConfig/index", data:"share_url="+encodeURIComponent(location.href)+"&format=jsonp&domain=m", type:'get', dataType:'jsonp', success:function(res){ if(res.status!="successed"){ return false; } $.getScript('https://res.wx.qq.com/open/js/jweixin-1.0.0.js',function(result,status){ if(status!="success"){ return false; } var getWxCfg=res.data; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId:getWxCfg.appId, // 必填,公众号的唯一标识 timestamp:getWxCfg.timestamp, // 必填,生成签名的时间戳 nonceStr:getWxCfg.nonceStr, // 必填,生成签名的随机串 signature:getWxCfg.signature,// 必填,签名,见附录1 jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口 wx.onMenuShareTimeline({ title: setWeixinShare.title, // 分享标题 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享给朋友”按钮点击状态及自定义分享内容接口 wx.onMenuShareAppMessage({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 type: setWeixinShare.type, // 分享类型,music、video或link,不填默认为link dataUrl: setWeixinShare.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ”按钮点击状态及自定义分享内容接口 wx.onMenuShareQQ({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 wx.onMenuShareWeibo({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口 wx.onMenuShareQZone({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); }); }); } }); } function openX_ad(posterid, htmlid, width, height) { if ($(htmlid).length > 0) { var randomnumber = Math.random(); var now_url = encodeURIComponent(window.location.href); var ga = document.createElement('iframe'); ga.src = 'https://www1.elecfans.com/www/delivery/myafr.php?target=_blank&cb=' + randomnumber + '&zoneid=' + posterid+'&prefer='+now_url; ga.width = width; ga.height = height; ga.frameBorder = 0; ga.scrolling = 'no'; var s = $(htmlid).append(ga); } } openX_ad(828, '#berry-300', 300, 250);