bluebit --- blue:bit驱动

blue:bit 模块提供bluebit套件的掌控板库。

http://wiki.labplus.cn/images/0/07/Bluebit套件1.png

NTC模块

class bluebit.NTC(pin)[源代码]

NTC 模块

参数:pin -- 掌控板引脚号,如使用P0,pin=0.
getTemper()[源代码]

获取温度

返回:温度,单位摄氏度

LM35模块

class bluebit.LM35(pin)[源代码]

LM35 模块

参数:pin -- 掌控板引脚号,如使用P0,pin=0.
getTemper()[源代码]

获取温度

返回:温度,单位摄氏度

四按键模块

class bluebit.joyButton(pin)[源代码]

四按键模块

参数:pin -- 掌控板引脚号,如使用P0,pin=0.
getVal()[源代码]

获取按键

返回:返回按键,值可以是'A','B','C','D',无按键按下'None'.

温湿度模块

class bluebit.SHT20(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[源代码]

温湿度模块SHT20控制类

参数:i2c -- I2C实例对象,默认i2c=i2c.
temperature()[源代码]

获取温度

返回:温度,单位摄氏度
humidity()[源代码]

获取湿度

返回:湿度,单位%

颜色模块

class bluebit.Color(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[源代码]

颜色模块控制类

参数:i2c -- I2C实例对象,默认i2c=i2c.
getRGB()[源代码]

获取RGB值

返回:返回RGB三元组,(r,g,b)
getHSV()[源代码]

获取HSV值

返回:返回HSV三元组,(h,s,v)

数字光线模块

class bluebit.AmbientLight(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[源代码]

数字光线模块控制类

参数:i2c -- I2C实例对象,默认i2c=i2c.
getLight()[源代码]

获取光线值

返回:返回光线值,单位lux

超声波模块

class bluebit.Ultrasonic(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[源代码]

超声波模块控制类

参数:i2c -- I2C实例对象,默认i2c=i2c.
distance()[源代码]

获取超声波测距

返回:返回测距,单位cm

4段数码管模块

class bluebit.SEGdisplay(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[源代码]

4段数码管模块tm1650控制类

参数:i2c -- I2C实例对象,默认i2c=i2c.
numbers(x)[源代码]

数字显示-999~9999

参数:x (int) -- 数字,范围-999~9999
Clear()[源代码]

数码管清屏

8x8点阵模块

class bluebit.Matrix(i2c=i2c)[源代码]

8x8点阵模块控制类

  • i2c : I2C实例对象,默认i2c=i2c.

设置像素点闪烁率

  • rate : 闪烁间隔时间,单位秒.默认None,常亮.
Matrix.brightness(brightness)

设置像素点亮度

  • brightness : 亮度级别,范围0~15.
Matrix.fill(color)

填充所有

  • color : 1亮;0灭
Matrix.bitmap(bitmap)

显示位图

  • bitmap : 8x8点阵数据
Matrix.show()

显示生效

除上述函数方法外,还继承 FrameBuffer 类 ,有关其他方法,如显示字符,绘制函数。详情可查阅 micropython framebuf模块 FrameBuffer 类.

LCD1602模块

class bluebit.LCD1602(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[源代码]

LCD1602模块控制类

参数:i2c -- I2C实例对象,默认i2c=i2c.
LEFT_TO_RIGHT

文本方向常量-从左到右

RIGHT_TO_LEFT

文本方向常量-从右到左

Init()[源代码]

1602初始化函数

Print(str)[源代码]

打印字符串

参数:str (str) -- 显示字符串,只支持英文.
Clear()[源代码]

清屏

setCursor(col, row)[源代码]

设置光标位置

参数:
  • col -- 列,1~16
  • col -- 行,1~2
Cursor(show)[源代码]

光标显示使能

参数:show (bool) -- True or False

光标闪烁使能

参数:blink (bool) -- True or False
display(enable)[源代码]

显示使能

参数:enable (bool) -- True or False
move_left()[源代码]

左滚动显示

move_right()[源代码]

右滚动显示

text_direction

文本方向

createChar(location, charmap=[])[源代码]

制作用户自定义 Fill one of the first 8 CGRAM locations with custom characters. The location parameter should be between 0 and 7 and pattern should provide an array of 8 bytes containing the pattern. E.g. you can easily design your custom character at http://www.quinapalus.com/hd44780udg.html To show your custom character use

参数:
  • location -- integer in range(8) to store the created character
  • pattern (~bytes) -- len(8) describes created character
Home()[源代码]

光标返回屏幕原点

MIDI模块

class bluebit.MIDI(tx)[源代码]

MIDI模块控制类

参数:i2c -- I2C实例对象,默认i2c=i2c.
volume

设置或返回音量

instrument

设置或返回音色

note(note, on_off)[源代码]

播放音符

参数:
  • note -- MIDI音符编码
  • on_off -- 音符播放或停止

MP3模块

class bluebit.MP3(tx)[源代码]

MP3模块控制类

参数:i2c -- I2C实例对象,默认i2c=i2c.
play_song(num)[源代码]

播放歌曲

参数:num (int) -- 歌曲编号,类型为数字
play()[源代码]

播放,用于暂停后的重新播放

playDir(dir, songNo)[源代码]

播放指定文件夹指定歌曲

参数:
  • dir (int) -- 文件夹编号,类型数字
  • songNo (int) -- 歌曲编号,类型为数字
playNext()[源代码]

播下一首

playPrev()[源代码]

播上一首

pause()[源代码]

暂停播放

stop()[源代码]

停止播放

volumeInc()[源代码]

增加音量

volumeDec()[源代码]

减小音量

loop(songNo)[源代码]

目录内指定序号歌曲循环播放

参数:songNo (int) -- 歌曲编号,类型为数字
loopDir(dir)[源代码]

指定目录内循环播放

参数:dir (int) -- 文件夹编号,类型数字
singleLoop(onOff)[源代码]

单曲循环开关

参数:onOff (int) -- 0:不循环 1:循环
volume

设置或返回音量设置,范围0~30

resetDevice()[源代码]

复位MP3

OLED模块

class bluebit.OLEDBit(rx, tx)[源代码]

bluebit OLED模块类

参数:rx,tx -- 接收,发送引脚
font_5x7

字体常量-5*7英文字体

font_song16

字体常量-16*16宋体

font_song24

字体常量-24*24宋体

font_consol32

字体常量-32*32宋体

Print(str, x, y, font=<sphinx.ext.autodoc.importer._MockObject object>)[源代码]

显示中英文字符串,支持字体 '0' =Font5x7, '1' = 宋体16x16, '2' = 宋体24x24, '3' = Consolas32x32

参数:
  • str (str) -- 中英文字符串
  • x y (int) -- 显示坐标
  • font -- 字体类型, font_5x7 , font_song24 , font_consol32 ;
clear(x0=0, y0=0, x1=127, y1=63)[源代码]

清除,默认全屏清除,也可以局部清除

参数:
  • x0 y0 (int) -- 抹去区域左上坐标
  • x1 y1 (int) -- 抹去区域右下坐标
show()[源代码]

显示生效,当使用framebuf类方法后使用show()刷新屏幕.

Bitmap(x, y, bitmap, w, h, c)[源代码]

显示图案

参数:
  • x y (int) -- 起点坐标
  • bitmap -- 图案1bit数据
  • w,h -- 图案宽高
  • c -- 颜色,1 or 0

红外接收模块

class bluebit.IRRecv(rx, uart_id=1)[源代码]

红外接收模块

参数:
  • rx -- 接收引脚设置
  • uart_id -- 串口号:1、2
recv()[源代码]

接收数据

Return int:返回红外值,类型整形

红外发射模块

class bluebit.IRTrans(tx, uart_id=2)[源代码]

红外发射模块

参数:
  • tx -- 发送引脚设置
  • uart_id -- 串口号:1、2
transmit(byte)[源代码]

发送数据

参数:byte (byte) -- 发送数据,单字节

实验探究类

适用的模块有电压、电流、磁场、电导率、PH、光电门、气压、力传感器。

class bluebit.DelveBit(address, i2c=<sphinx.ext.autodoc.importer._MockObject object>)[源代码]

实验探究类的blue:bit,适用的模块有电压、电流、磁场、电导率、PH、光电门、气压、力传感器

参数:
  • address -- 模块的I2C地址,可再模块拨动选择不同的地址避免冲突。
  • i2c -- I2C实例对象,默认i2c=i2c
common_measure()[源代码]

获取实验探究类传感器测量值的通用函数

Return int:返回传感器测量值,单位:电压(V)、电流(A)、磁场(mT)、电导率(uS/cm)、PH(pH)、光电门(s)、气压(kPa)、力传感器(N)
photo_gate()[源代码]

Photogate Timer 是用来记录刚触发时刻和触发结束时刻的时间。计算信号的正脉宽时间,当输入信号由低变高为触发开始点,由高变低位触发触发结束点,计算之间的时间差。

Return int:返回正脉宽时间,单位秒

编码电机模块

class bluebit.EncoderMotor(address, i2c=<sphinx.ext.autodoc.importer._MockObject object>)[源代码]

blue:bit编码电机驱动,提供pwm、cruise、position 三种驱动方式。

参数:
  • address -- 模块的I2C地址,可再模块拨动选择不同的地址避免冲突。
  • i2c -- I2C实例对象,默认i2c=i2c
PWM_MODE = b'\x05'

pwm模式

CRUISE_MODE = b'\n'

巡航模式

POSITION_MODE = b'\x0f'

定位模式

motor_stop()[源代码]

停止编码电机转动

set_pwm(speed1, speed2)[源代码]

pwm模式

参数:
  • speed1 -- 设置M1通道编码电机速度,范围-1023~1023
  • speed2 -- 设置M2通道编码电机速度,范围-1023~1023
set_cruise(speed1, speed2)[源代码]

Cruise巡航模式,设定速度后,当编码电机受阻时,会根据反馈,自动调整扭力,稳定在恒定的速度。

参数:
  • speed1 -- 设置M1通道编码电机速度,范围-1023~1023
  • speed2 -- 设置M2通道编码电机速度,范围-1023~1023
set_position(turn1, turn2)[源代码]

定位模式,可设置编码编码电机定点位置,范围-1023~1023。

参数:
  • turn1 -- 设置M1通道编码电机定位,-1023~1023
  • turn2 -- 设置M2通道编码电机定位,-1023~1023