发 帖  

【MiCOKit试用体验】项目结贴------四驱调速车

2015-9-25 19:17:48  8151 Android

  •                

  •                                 

  •                                 

  •                                 

  •                         

  •         
  • 复制代码
    下面这是按钮控制代码:

    1. //电机开关
    2.                 $("#motorbtn").click(function() {
    3.                         var topic = device_id + '/in';
    4.                         var command;
    5.                         var mtbtn = $("#motorbtn");
    6.                         if (mtbtn.attr("src") == "../image/smallicon-9kaiguan.png") {
    7.                                 mtbtn.attr("src", "../image/smallicon-8kaiguan.png");
    8.                                 command = '{"switch_motor":false}';
    9.                         } else {
    10.                                 mtbtn.attr("src", "../image/smallicon-9kaiguan.png");
    11.                                 command = '{"switch_motor":true}';
    12.                         }
    13.                         publishcmd(topic, command);
    14.                 });
    15.                
    16.                 //控制RGB的开关
    17.                 /*function powerctrl(pwtag) {
    18.                         var topic = device_id + '/in';
    19.                         var command;
    20.                         if ("on" == pwtag)
    21.                                 command = '{"rgbled_switch":true}';
    22.                         else if ("off" == pwtmotorag)
    23.                                 command = '{"rgbled_switch":false}';
    24.                         publishcmd(topic, command);
    25.                 }*/

    26.                 //速度按钮处理
    27.                 $("#y500btnid").click(function() {
    28.                         var topic = device_id + '/in';
    29.                         var command = '{"motor_speed":200}';//'{"rgbled_switch":true,"rgbled_hues":0, "rgbled_saturation":100, "rgbled_brightness":100}';
    30.                         publishcmd(topic, command);
    31.                 });
    32.                 $("#g2000btnid").click(function() {
    33.                         var topic = device_id + '/in';
    34.                         var command = '{"motor_speed":500}';
    35.                         publishcmd(topic, command);
    36.                 });
    37.                 $("#r3500btnid").click(function() {
    38.                         var topic = device_id + '/in';
    39.                         var command = '{"motor_speed":800}';
    40.                         publishcmd(topic, command);
    41.                 });
    42.                 $("#y1000btnid").click(function() {
    43.                         var topic = device_id + '/in';
    44.                         var command = '{"motor_speed":300}';
    45.                         publishcmd(topic, command);
    46.                 });
    47.                 $("#g2500btnid").click(function() {
    48.                         var topic = device_id + '/in';
    49.                         var command = '{"motor_speed":600}';
    50.                         publishcmd(topic, command);
    51.                 });
    52.                 $("#r4000btnid").click(function() {
    53.                         var topic = device_id + '/in';
    54.                         var command = '{"motor_speed":900}';
    55.                         publishcmd(topic, command);
    56.                 });
    57.                 $("#y1500btnid").click(function() {
    58.                         var topic = device_id + '/in';
    59.                         var command = '{"motor_speed":400}';
    60.                         publishcmd(topic, command);
    61.                 });
    62.                 $("#g3000btnid").click(function() {
    63.                         var topic = device_id + '/in';
    64.                         var command = '{"motor_speed":700}';
    65.                         publishcmd(topic, command);
    66.                 });
    67.                 $("#r4500btnid").click(function() {
    68.                         var topic = device_id + '/in';
    69.                         var command = '{"motor_speed":1000}';
    70.                         publishcmd(topic, command);
    71.                 });
    复制代码


    最后实现效果如下:

    singn.png

    大致解释一下,通过按下图片按钮,会像云端提交一个JSON数据,再被设备解析,设备再改变占空比实现调速。

    设备端借鉴了阿莫论坛上某个人的帖子,这我删除了大量无关代码,具体怎么修改,可以查看一下我上一篇【MiCOKit试用体验】APP端之电机添加

    。其他就不多说了。
    下面这图是运行流程:
    QQ图片20150928102507.png
    下面附上装载图:
    IMG_20150928_123301.jpg IMG_20150928_123306.jpg
    下面是演示效果:









    ` IMG_20150928_123310.jpg
    1
  • 2015-9-25 19:17:48   评论 分享淘帖
    4 个讨论
    2015-9-28 15:33:01 评论

    举报

    2015-9-28 21:39:10 评论

    举报

    2015-9-30 21:26:50 评论

    举报

    2015-12-15 16:52:11 评论

    举报

    只有小组成员才能发言,加入小组>>

    98个成员聚集在这个小组

    加入小组

    精选推荐

    最新话题

      热门话题

        创建小组步骤

        快速回复 返回顶部 返回列表
        关注微信公众号

        电子发烧友网

        电子发烧友论坛

        社区合作
        刘勇
        联系电话:15994832713
        邮箱地址:liuyong@huaqiu.com
        社区管理
        elecfans短短
        微信:elecfans_666
        邮箱:users@hauqiu.com
        关闭

        站长推荐 上一条 /6 下一条

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