
使用加速度计的同步控制汽车
本記事にはアフィリエイト広告が含まれます。
我曾经在斯林克的模糊通信中创建了一个无线电控制控制。
https://homemadegarbage.com/zh/blynk_car01-3
有一个更新的 Blynk (v0.4.4) 和 ble 通信是正式引入, 而不是测试版, 进一步, 因为智能手机的加速度传感器信息已经能够获得, 我试图修改无线电控制倾斜智能 手机。
我一点也不努力 (^o^)。
目次
arduino 的 blynk 图书馆
最新的库位于以下位置: https://github.com/blynkkk/blynk-library
使用 adafruit 羽毛32u4 蓝果 le。因此, arduino 代码是参照以下内容生成的。
[Example] -> [Blynk] -> [Boards_Bluetooth]-> [Adafruit_Feather_32u4_BLE]
混合设置
创建新项目。选择硬件模式中的 arduino uno, 因为还没有 Adafruit 羽毛 32u4 ble。连接类型为 “双”。auth token 将做一个笔记, 以便您在生成 arduino 代码 (或发送邮件) 时使用它。
 
放置 ble 小部件和加速度计小部件。
 
加速度计设置。这些值在虚拟引脚 v0 中输出。
arduino ide
[Example] -> [Blynk] -> [Boards_Bluetooth]-> [Adafruit_Feather_32u4_BLE] 由引用生成的代码。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | //#define BLYNK_DEBUG #define BLYNK_PRINT Serial #define BLYNK_USE_DIRECT_CONNECT #include <BlynkSimpleSerialBLE.h> #include <SPI.h> #include <Adafruit_BLE.h> #include <Adafruit_BluefruitLE_SPI.h> // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = "YourAuthToken"; // SHARED SPI SETTINGS (see adafruit webpages for details) #define BLUEFRUIT_SPI_CS               8 #define BLUEFRUIT_SPI_IRQ              7 #define BLUEFRUIT_SPI_RST              4    // Optional but recommended, set to -1 if unused #define BLUEFRUIT_VERBOSE_MODE         true // Create ble instance, see pinouts above Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST); //pin name const int  forwardL = 11; const int  rearL = 10; const int  forwardR = 5; const int  rearR = 6; long Speed; long SpeedL, SpeedR; BLYNK_WRITE(V0) {   int x = param[0].asFloat();   int y = param[1].asFloat();   x = map(x, -10, 10, 255, -255);   y = map(y, -10, 10, 255, -255);   Serial.print("x: ");   Serial.print(x);   Serial.print("  y: ");   Serial.print(y);   Speed = sqrt(x*x+y*y);   if(Speed > 255){     Speed = 255;   }   Serial.print("  Speed: ");   Serial.println(Speed);   if(y >= 0){     if(x >= 0){       SpeedL = 0;       SpeedR = abs(x);     }else{       SpeedL = abs(x);       SpeedR = 0;     }     analogWrite(forwardL, Speed - SpeedL);     analogWrite(rearL, 0);     analogWrite(forwardR, Speed - SpeedR);     analogWrite(rearR, 0);   }else{     if(x >= 0){       SpeedL = 0;       SpeedR = abs(x);     }else{       SpeedL = abs(x);       SpeedR = 0;     }     analogWrite(forwardL, 0);     analogWrite(rearL, Speed - SpeedL);     analogWrite(forwardR, 0);     analogWrite(rearR, Speed - SpeedR);   } } void setup() {   Serial.begin(9600);   ble.begin(BLUEFRUIT_VERBOSE_MODE);   ble.factoryReset(); // Optional   ble.setMode(BLUEFRUIT_MODE_DATA);   Blynk.begin(auth, ble); } void loop() {   Blynk.run(); } | 
操作由智能手机屏幕的水平 (重力) 加速度值 [x, y] 控制的无线电。
混入式连接
单击项目的 ble 小部件。
 
点击 “Connect BLE device”。
 
然后通过点击 “OK” 连接到 “Adafruit Bluefruit LE”。
经营
多亏了 Blynk, 它似乎能够做各种事情直观脆, 因为智能手机和设备的合作可以是疯狂的容易
 お父ちゃん 
             2017.1.29
            お父ちゃん 
             2017.1.29 
          





 
		 
		 
		 
		 
		