清泛IT社区

标题: APP INVENTOR硬件交互学习教程04——蓝牙控制继电器 [打印本页]

作者: mzb2012    时间: 5 天前
标题: APP INVENTOR硬件交互学习教程04——蓝牙控制继电器
这节主要是设计一个APP,连接蓝牙模块,通过按钮控制继电器的打开和关闭。

一、硬件部分

二、板子程序
串口接收字符,并输出控制继电器


  1. // 引脚定义
  2. const int ledPin1 =  5;// the number of the LED pin
  3. const int ledPin2 =  6;
  4. const int ledPin3 =  3;
  5. const int bluePin =  6;// the number of the LED pin
  6. const int greenPin =  5;
  7. const int redPin =  3;
  8. const int beepPin =  15;
  9. const int relayPin =  14;
  10. const int keyPin1 =  2;
  11. const int keyPin2 =  4;
  12. const int keyPin3 =  7;
  13. const int bluetoothPin = 13;

  14. // 变量定义

  15. int inByte=0;   //接收参数

  16. #define TRUE 1
  17. #define FALSE 0
  18. void setup()
  19. {
  20.   // 配置输出引脚
  21.   pinMode(ledPin1, OUTPUT);
  22.   pinMode(ledPin2, OUTPUT);
  23.   pinMode(ledPin3, OUTPUT);
  24.   pinMode(beepPin, OUTPUT);
  25.   pinMode(relayPin, OUTPUT);
  26.   // 配置输入引脚
  27.   pinMode(keyPin1, INPUT);
  28.   pinMode(keyPin2, INPUT);
  29.   pinMode(keyPin3, INPUT);
  30.   pinMode(bluetoothPin, INPUT);
  31.   // 配置串口
  32.   Serial.begin(9600);

  33. }
  34. void loop() {
  35.   if(Serial.available()) {
  36.   inByte = Serial.read();
  37.   
  38.     if(inByte == 'H'){ digitalWrite(relayPin, HIGH);}
  39.     if(inByte == 'L'){ digitalWrite(relayPin, LOW);}
  40.    
  41.   } }
复制代码
三、app inventor
3.1界面
(, 下载次数: 2)


3.2程序逻辑块
(, 下载次数: 3)





欢迎光临 清泛IT社区 (https://bbs.tsingfun.com/) Powered by Discuz! X3.3