and SPI. 一个控制打开某个串口针脚的基础库
先介绍一些树莓派的入门教程
阮一峰的树莓派入门
微雪电子-树莓派硬件中文官网
ssh链接树莓派
ssh [email protected](ip)
暗码:raspberry
设置显示设备
保举选购3.5吋或者5吋的HDMI显示设备,我第一次买的3.2吋的串口显示器,占用了我20个串口的针脚。
设备链接见这里
使用3.5吋显示器
cd /boot/LCD-show/
./LCD35-show
使用HDMI输出
cd /boot/LCD-show/
./LCD-hdmi
设置旋转屏幕
设置显示标的目的
安置完触摸驱动后,可以通过运行以下命令改削屏幕旋转标的目的。
旋转0度:
cd /boot/LCD-show/
./LCD35-show 0
旋转90度:
cd /boot/LCD-show/
./LCD35-show 90
旋转180度:
cd /boot/LCD-show/
./LCD35-show 180
旋转270度:
cd /boot/LCD-show/
./LCD35-show 270
声音设置为非HDMI输出
Bash
sudo amixer cset numid=3 1
需要注意的是如果你是浏览器播放声音。。拔失显示器后貌似浏览器就进入后台模式不播放声音了。
介绍一些相关的nodejs的库
https://github.com/rwaldron/j...
一个适配各类板子的串口的根本库,当你需要点亮LED小灯泡的时候需要用到它
Raspi-io
Raspi-io is a Firmata API compatible library for Raspbian running on the Raspberry Pi that can be used as an I/O plugin with Johnny-Five.
和上面一个库搭配使用。
rpio
https://github.com/jperkin/no...
This is a high performance node.js addon which provides access to the Raspberry Pi GPIO interface, supporting regular GPIO as well as i2c, PWM, and SPI.
一个控制打开某个串口针脚的根本库。
serialport
https://github.com/EmergingTe...
一个链接控制硬件的根本库,好比控制USB串口,,和链接USB串口的设备进行通信等,他有很多版本,树莓派的版本见这里
安置有点,麻烦。我折腾了3小时、、、、
点亮一个LED灯
LED灯分为简单的两个针脚的二极管灯,点亮见前面阮一峰博客,下面重点介绍一下RGB的LED灯
如上所示。这样的灯点亮的教程对照少。
第一步选择对应的串口针脚,首先不要把插针脚2,即:+5V口阿谁。
我插了两个分袂是RGB为:[29,31,33],[36,38,40]
代码如下
var five = require("johnny-five"); var Raspi = require(‘raspi-io‘) var rpio = require(‘rpio‘); var isLED1On=false; var isLED2On=false; var LED = { LED1:null, LED2:null, init(LED1=[29,31,33],LED2=[36,38,40]){ var board = new five.Board({ io:new Raspi({enableSoftPwm:true}) }); this.LED1=LED1; this.LED2=LED2 board.on(‘ready‘,function(){ return new Promise(function(resolve,reject){ var led1 = new five.Led.RGB({ pins: { red: `P1-${LED1[0]}`, green: `P1-${LED1[1]}`, blue:`P1-${LED1[2]}`, } }) var led2 = new five.Led.RGB({ pins: { red: `P1-${LED2[0]}`, green: `P1-${LED2[1]}`, blue:`P1-${LED2[2]}`, } }) // 打开 11 号针脚(GPIO17) 作为输出 rpio.open(LED1[0], rpio.OUTPUT); rpio.open(LED1[1], rpio.OUTPUT); rpio.open(LED1[2], rpio.OUTPUT); rpio.open(LED2[0], rpio.OUTPUT); rpio.open(LED2[1], rpio.OUTPUT); rpio.open(LED2[2], rpio.OUTPUT); rpio.open(LED1[0], rpio.HIGH); rpio.open(LED1[1], rpio.HIGH); rpio.open(LED1[2], rpio.HIGH); resolve(board); }) }) }, openLED1(){ console.log(‘led1‘+JSON.stringify(this)) rpio.write(this.LED1[0], rpio.HIGH); rpio.write(this.LED1[1], rpio.HIGH); rpio.write(this.LED1[2], rpio.HIGH); isLED1On=true; }, openLED2(){ rpio.write(this.LED2[0], rpio.HIGH); rpio.write(this.LED2[1], rpio.HIGH); rpio.write(this.LED2[2], rpio.HIGH); isLED2On=true; }, closeLED1(){ console.log(‘led1‘+JSON.stringify(this)) rpio.write(this.LED1[0], rpio.LOW); rpio.write(this.LED1[1], rpio.LOW); rpio.write(this.LED1[2], rpio.LOW); isLED1On=false; }, closeLED2(){ rpio.write(this.LED2[0], rpio.LOW); rpio.write(this.LED2[1], rpio.LOW); rpio.write(this.LED2[2], rpio.LOW); isLED2On=false; }, flashLED1(){ if(isLED1On){ return; } var self = this; self.openLED1(); setTimeout(function () { self.closeLED1(); },3000); }, flashLED2(){ if(isLED2On){ return; } var self = this; self.openLED2(); setTimeout(function () { self.closeLED2() },3000); }, } module.exports={ led:LED }更多内容详见我的博客
nodejs和树莓派开发以及点亮RGB的LED灯代码
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31235.html
- 上一篇:便可以得到测试结果了
- 下一篇:对于Java开发者来说