candyling的个人空间 https://www.eechina.com/space-uid-142796.html [收藏] [复制] [RSS]

博客

钛极OS(TiJOS)物联网操作系统之小试牛刀(3)——红外遥控

已有 1049 次阅读2018-3-16 15:24

说明

开发环境的搭建以及应用工程的创建方法在这里不再赘述,可参考笔者文章《钛极OS(TiJOS)物联网操作系统之初体验》或访问钛极OS(TiJOS)系统官方发布的教程☞钛极OS(TiJOS)应用开发环境搭建

功能实现

解码红外遥控编码,编码方式为NEC码,并将遥控编码在屏幕上显示(支持重复码的接收显示)。

硬件准备
  1. TiKit-T600-ESP8266A 开发板
  2. TiVS1838BNEC红外接收模块
  3. TiOLED_UG2864显示模块(OLED12864)
  4. 红外线遥控器(迷你版)
  5. 杜邦线若干
  6. USB线两条
硬件连接

TiKit开发板<——连接——>TiOLED_UG2864显示模块

SCL <——连接——>SCL

SDA <——连接——>SDA

3.3V <——连接——>VCC

GND <——连接——>GND

===================================

TiKit开发板<——连接——>TiVS1838BNEC红外接收模块

PIN3 <——连接——>OUT

3.3V <——连接——>VCC

GND <——连接——>GND

===================================

hardware

程序编写

在Eclipse中新建TiJOS Application工程,编写JAVA代码如下:

import java.io.IOException; import tijos.framework.devicecenter.TiGPIO; import tijos.framework.devicecenter.TiI2CMaster; import tijos.framework.sensor.infrared.ITiVS1838BNECEventListener; import tijos.framework.sensor.infrared.TiVS1838BNEC; import tijos.framework.transducer.led.TiOLED_UG2864; import tijos.util.Delay; class DecodingEventListener implements ITiVS1838BNECEventListener { private TiOLED_UG2864 _oled; public DecodingEventListener(TiOLED_UG2864 oled) { this._oled = oled; } /** * 接收事件处理 */ public void cmdReceived(TiVS1838BNEC arg0) { try { _oled.print(1, 0, "ADDR:"+arg0.getAddress()); _oled.print(2, 0, "CODE:"+arg0.getCommand()); _oled.print(3, 0, "REPEAT:No "); } catch(IOException e) { e.printStackTrace(); } } /** * 接收重复事件处理 */ public void cmdRepeat(TiVS1838BNEC arg0) { try { _oled.print(3, 0, "REPEAT:Yes"); } catch(IOException e) { e.printStackTrace(); } } } /** * 解码红外遥控编码,编码方式为NEC码,并将遥控编码在屏幕上显示(支持重复码的接收显示)。 * * @author crashMaker * */ public class Decoding { public static void main(String[] args) { try { //定义要使用的I2C接口 int i2cPort = 0; //定义要使用的GPIO接口和PIN资源 int goioPort = 0; int outPin = 3; //打印日志 System.out.println("This is a infrared decoding test."); //分配I2C和GPIO资源 TiI2CMaster i2c = TiI2CMaster.open(i2cPort); TiGPIO gpio = TiGPIO.open(goioPort, outPin); //绑定资源到实例,完成与硬件的映射 TiOLED_UG2864 oled = new TiOLED_UG2864(i2c, 0x78); TiVS1838BNEC vs1838b = new TiVS1838BNEC(gpio, outPin); //创建解码事件监听对象,并设置监听者 DecodingEventListener lc = new DecodingEventListener(oled); vs1838b.setEventListener(lc); //显示屏幕打开,并显示信息 oled.turnOn(); oled.clear(); oled.print(0, 0, "===crashMaker==="); //保证主线程不退出 while(true) { //线程睡眠1秒 Delay.msDelay(1000); } } catch(IOException e) { e.printStackTrace(); } } }
  • 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
功能演示

在Eclipse中执行“Run As TiJOS Application”,运行编写的应用程序,演示效果如下:

test

应用运行后,在Eclipse中打印日志如下:

log


路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
返回顶部