blinker改造线控玩具坦克-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2477|回复: 4

[分享] blinker改造线控玩具坦克

[复制链接]
发表于 2020-6-2 17:47 | 显示全部楼层 |阅读模式
  闲暇之时将孩子儿时的线控玩具坦克改成了blinker控制的遥控坦克.首先更换了原来耗电量很大的旧电机,然后新设计增加了声光炮击电路和探照灯电路.又选
用舵机电路来控制炮台旋转功能,通过滑块来调节方向和角度.最后对新增的6V镍氢电池组设计了充电保护电路,利用了8266的ADC端口监控电池电压,确保充电终止
电压在7V左右.而且在blinker app上也设有电压数据块可实时显示电池电压.
  程序与电路图如下:

#define BLINKER_WIFI
#include <Blinker.h>
#include <Servo.h>
Servo myservo;  

char auth[]="******";
char ssid[]="******";
char pswd[]="******";
BlinkerNumber Battery("dy");
BlinkerSlider Slider1("fx");
BlinkerButton Button("dd");
BlinkerButton Button1("rb");
BlinkerButton Button2("lb");
BlinkerButton Button3("lf");
BlinkerButton Button4("rf");
BlinkerButton Button5("ff");
int k0=95;
int k1=95;
int val=0;
int pos=95;
int dy_read=0;
void slider1_callback(int32_t value)
{
    BLINKER_LOG("get slider value: ", value);
    k1=180-value;
}
void button_callback(const String & state)  
{
  BLINKER_LOG("get button state: ", state);
  if (state=="on")
   {
     Button.icon("fas fa-lightbulb");//fa-lightbulb
        Button.color("#FF0000");
        Button.text("开");
    digitalWrite(0, HIGH);
     Button.print("on");
    }
    else if(state=="off")
    {
       Button.icon("fal fa-lightbulb");
        Button.color("#FF0000");
        Button.text("关");
      digitalWrite(0, LOW);  
      Button.print("off");
     }
}
void button1_callback(const String & state)  
{
  BLINKER_LOG("get button state: ", state);
  if (state == BLINKER_CMD_BUTTON_PRESSED)
   {
     Button1.icon("fas fa-arrow-alt-down");//fa-lightbulb
        Button1.color("#00FF00");
        Button1.text("开");
    digitalWrite(14, HIGH);
     Button1.print("on");
    }
    else if(state == BLINKER_CMD_BUTTON_RELEASED)
    {
       Button1.icon("fal fa-arrow-alt-down");
        Button1.color("#0000FF");
        Button1.text("关");
      digitalWrite(14, LOW);   
      Button1.print("off");
     }
}
void button2_callback(const String & state)   
{
  BLINKER_LOG("get button state: ", state);
  if (state == BLINKER_CMD_BUTTON_PRESSED)
   {
     Button2.icon("fas fa-arrow-alt-down");//fa-lightbulb
        Button2.color("#00FF00");
        Button2.text("开");
    digitalWrite(12, HIGH);
     Button2.print("on");
    }
    else if(state == BLINKER_CMD_BUTTON_RELEASED)
    {
       Button2.icon("fal fa-arrow-alt-down");
        Button2.color("#0000FF");
        Button2.text("关");
      digitalWrite(12, LOW);  
      Button2.print("off");
     }
}
void button3_callback(const String & state)   
{
  BLINKER_LOG("get button state: ", state);
  if (state == BLINKER_CMD_BUTTON_PRESSED)
   {
     Button3.icon("fas fa-arrow-alt-up");//fa-lightbulb
        Button3.color("#00FF00");
        Button3.text("开");
    digitalWrite(13, HIGH);
     Button3.print("on");
    }
    else if(state == BLINKER_CMD_BUTTON_RELEASED)
    {
       Button3.icon("fal fa-arrow-alt-up");
        Button3.color("#0000FF");
        Button3.text("关");
      digitalWrite(13, LOW);
      Button3.print("off");
     }
}
void button4_callback(const String & state)  
{
  BLINKER_LOG("get button state: ", state);
  if (state == BLINKER_CMD_BUTTON_PRESSED)
   {
     Button4.icon("fas fa-arrow-alt-up");//fa-lightbulb
        Button4.color("#00FF00");
        Button4.text("开");
    digitalWrite(16, HIGH);
     Button4.print("on");
    }
    else if(state == BLINKER_CMD_BUTTON_RELEASED)
    {
       Button4.icon("fal fa-arrow-alt-up");
        Button4.color("#0000FF");
        Button4.text("关");
      digitalWrite(16, LOW);
      Button4.print("off");
     }
}
void button5_callback(const String & state)   
{
  BLINKER_LOG("get button state: ", state);
  if (state == BLINKER_CMD_BUTTON_PRESSED)
   {
     Button5.icon("fas fa-burn");//fa-lightbulb
        Button5.color("#FF0000");
        Button5.text("开");
    digitalWrite(2, HIGH);
     Blinker.delay(100);
    digitalWrite(2, LOW);
     Button5.print("on");
    }
    else if(state == BLINKER_CMD_BUTTON_RELEASED)
    {
       Button5.icon("fal fa-burn");
        Button5.color("#FF0000");
        Button5.text("关");
      digitalWrite(2, LOW);  
      Button5.print("off");
     }
}
void dataRead(const String & data)
{
    BLINKER_LOG("Blinker readString: ", data);
    Blinker.vibrate();
    uint32_t BlinkerTime = millis();
  Blinker.print(BlinkerTime);
    Blinker.print("millis", BlinkerTime);
}
void heartbeat()
{
  Battery.print(dy_read);
}
void setup()
{
  Serial.begin(115200);
  BLINKER_DEBUG.stream(Serial);

  BLINKER_DEBUG.debugAll();
   pinMode(2, OUTPUT);
   pinMode(0, OUTPUT);
   pinMode(12, OUTPUT);
   pinMode(16, OUTPUT);
   pinMode(13, OUTPUT);
    pinMode(14, OUTPUT);
   pinMode(15, OUTPUT);
   pinMode(4,OUTPUT);
  digitalWrite(2, LOW);
   digitalWrite(0, LOW);
  digitalWrite(12, LOW);
digitalWrite(13, LOW);
digitalWrite(14, LOW);
digitalWrite(16, LOW);
digitalWrite(15, LOW);
pinMode(A0,INPUT);
  myservo.attach(4);
  Blinker.begin(auth,ssid,pswd);
Blinker.attachHeartbeat(heartbeat);
  Button.attach(button_callback);
  Slider1.attach(slider1_callback);
  Button1.attach(button1_callback);
  Button2.attach(button2_callback);
  Button3.attach(button3_callback);
  Button4.attach(button4_callback);
  Button5.attach(button5_callback);
   Blinker.attachData(dataRead);
}  
void loop()
{
    Blinker.run();
    val=analogRead(A0);
     dy_read=val*70/8;
  if(val>800) digitalWrite(15,LOW);
  else digitalWrite(15,HIGH);

  if(k1>k0) {
  for (pos = k0; pos <= k1; pos += 1) {
    myservo.write(pos);              
    delay(50);                     
  }
  k0=k1;
  }
  else {
  for (pos = k0; pos >= k1; pos -= 1) {
    myservo.write(pos);            
    delay(50);                     
  }
  k0=k1;
  }
  Blinker.delay(1000);  
}

app界面

app界面

电路图

电路图

坦克内部照片

坦克内部照片

坦克外观照片

坦克外观照片
发表于 2020-6-5 00:31 | 显示全部楼层
学到一点,心跳传num数据,,,

另问一下,这个是ESP32么?  烧写程序的时候拿什么传的呀?  用esp01s那个usb-ttl的可以吗?
 楼主| 发表于 2020-6-5 09:55 | 显示全部楼层
chuckbei 发表于 2020-6-5 00:31
学到一点,心跳传num数据,,,

另问一下,这个是ESP32么?  烧写程序的时候拿什么传的呀?  用esp01s那个usb ...

我用的是ESP8266机智云开发板,它本身带烧写底座 ,可看掏宝链接 https://item.taobao.com/item.htm ... ;abbucket=18#detail
只要端口够任何8266开发板都可以用.
发表于 2020-6-7 20:46 | 显示全部楼层
可以加个好友吗?想问问你的设计
 楼主| 发表于 2020-6-8 04:48 | 显示全部楼层
q1127957008 发表于 2020-6-7 20:46
可以加个好友吗?想问问你的设计

可以,是论坛好友吗?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 09:24 , Processed in 0.110722 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表