Weeemake Arduino Libaries API Reference
RGB超声波传感器API
class WeUltrasonicSensor
描述:超声波传感器类名定义
其可直接调用的成员函数如下:
(1) WeUltrasonicSensor(uint8_t port=0)
描述:构造函数,在定义超声波类时可定义接口
参数:
port |
选择端口,如PORT_A,PORT_1等 |
返回值:无
示例:WeUltrasonicSensor ultrasonic_sensor(PORT_A);
备注:在定义类时,可以不直接传入port的值(初值为0),可之后设置:
WeUltrasonicSensor ultrasonic_sensor;
之后调用:ultrasonic_sensor.reset(PORT_A);
(2) void reset(uint8_t port=0)
描述:可重新设置接口
参数:
port |
选择端口,如PORT_A,PORT_1等 |
返回值:无
(3) double distanceCm(void)
描述:获取超声波测距数据
参数:无
返回值:双精度浮点数,范围3~500,单位:厘米
(4) void setColor(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)
描述:设置超声波内置RGB灯的显示颜色并显示
参数:
index |
选择RGB灯,范围1~3,1为左,2为右,3为全部 |
red |
红色分量设置(0~255) |
green |
绿色分量设置(0~255) |
blue |
蓝色分量设置(0~255) |
返回值:无
(5) void setLed(uint8_t index, bool isOn);
描述:驱动Mini RGB超声波传感器板载上两颗黄色LED灯
参数:
index |
选择LED灯,范围1~3,1为左,2为右,3为全部 |
isOn |
设置LED灯的状态,0为灭,1为亮 |
返回值:无
编程示例:
#include "WeELF328P.h" WeUltrasonicSensor ultraSensor(PORT_B); void setup() { Serial.begin(9600); } void loop() { ultraSensor.setColor(1,0,20,0); //(Red,Green,Blue) ultraSensor.setColor(2,20,0,0); //(Red,Green,Blue) Serial.print("Distance : "); Serial.print(ultraSensor.distanceCm() ); Serial.println(" cm"); delay(100); }
巡线传感器API
1. 双路巡线传感器API
class WeLineFollower
描述:双路巡线传感器类名定义
其可直接调用的成员函数如下:
(1) WeLineFollower(uint8_t port=0)
描述:构造函数,在定义超声波类时可定义接口
参数:
port |
选择端口,如PORT_A,PORT_1等 |
返回值:无
示例:WeLineFollower linefollower_sensor(PORT_A);
备注:在定义类时,可以不直接传入port的值(初值为0),可之后设置:
WeLineFollower linefollower_sensor;
之后调用:linefollower_sensor.reset(PORT_A);
(2) void reset(uint8_t port=0)
描述:可重新设置接口
参数:
port |
选择端口,如PORT_A,PORT_1等 |
返回值:无
(3) uint16_t startRead(uint8_t index)
描述:获取巡线探头测量数据
参数:
index |
选择探头,1为S1,2为S2 |
返回值:整数,范围0~1023
编程示例:
#include "WeELF328P.h" WeLineFollower lineFollower(PORT_A); void setup() { Serial.begin(9600); } void loop() { uint16_t s1,s2; s1=lineFollower.startRead(1); s2=lineFollower.startRead(2); Serial.print("S1="); Serial.println(s1); Serial.print("S2="); Serial.println(s2); delay(100); }
2. 单路巡线传感器API
class WeSingleLineFollower
(1) WeSingLineFollower(uint8_t port=0)
描述:构造函数,在定义超声波类时可定义接口
参数:
port |
选择端口,只能选择模拟口,ELF主控板的PORT_1~PORT_6,ELF MINI主控板的PORT_A~PORT_D |
返回值:无
(2) uint16_t read(void)
描述:获取巡线探头测量数据
参数:无
返回值:整数,范围0~1023
编程示例:
#include<WeELF328P.h> WeSingleLineFollower slf_sensor(PORT_3); void setup() { Serial.begin(9600); } void loop() { uint16_t value = slf_sensor.read(); Serial.println(value); delay(100) }
LED表情面板模块API
MP3模块API
class WeMP3
描述:MP3模块类名定义
其可直接调用的成员函数如下:
(1) WeMP3(uint8_t port=0)
描述:构造函数,在定义MP3类时可定义接口
参数:
port |
选择端口,如PORT_A,PORT_1等 |
返回值:无
示例:WeMP3 mp3(PORT_A);
备注:在定义类时,可以不直接传入port的值(初值为0),可之后设置:
WeMP3 mp3;
之后调用:mp3.reset(PORT_A);
(2) void reset(uint8_t port=0)
描述:可重新设置接口
参数:
port |
选择端口,如PORT_A,PORT_1等 |
返回值:无
(3) void appointDevice(uint8_t devtype);
描述:设置曲目播放来源,内置FLASH或TF卡
参数:
devtype |
选择播放文件来源,2为TF卡,4为内置FLASH |
返回值:无
(4) void appointVolume(uint8_t volume)
描述:设置播放音量
参数:
volume |
音量值,范围(0~30) |
返回值:无
(5) void appointMusic(uint16_t num)
描述:指定播放第几首
参数:
num |
选择第几首,范围(0~3000) |
返回值:无
(6) void play(void)
描述:播放
参数:无
返回值:无
(7) void pause(void)
描述:暂停播放
参数:无
返回值:无
(8) void prevMusic(void)
描述:上一首
参数:无
返回值:无
(9) void nextMusic(void)
描述:下一首
参数:无
返回值:无
(10) uint8_t isOver(void)
描述:判断当前曲目是否播放完毕
参数:无
返回值:1表示播放完毕,0表示未播放完
#include "WeELF328P.h" WeMP3 mp3(PORT_A); void setup() { mp3.appointVolume(20); //Volume 0~23 mp3.appointDevice(4); //2-TF; 4-FLASH mp3.appointMusic(1); //0~3000 } void loop() { if(mp3.isOver()==1) { mp3.nextMusic(); } }
电子指南针传感器API
class WeCompassSensor
描述:电子罗盘传感器类名定义
其可直接调用的成员函数如下:
(1) WeCompassSensor(uint8_t port=0)
描述:构造函数,在定义电子罗盘传感器类时可定义接口
参数:
port |
选择端口,如PORT_A,PORT_1等 |
返回值:无
示例:WeCompassSensor compass(PORT_A);
备注:在定义类时,可以不直接传入port的值(初值为0),可之后设置:
WeCompassSensor compass;
之后调用:compass.reset(PORT_B);
(2) void reset(uint8_t port=0)
描述:可重新设置接口
参数:
port |
选择端口,如PORT_A,PORT_1等 |
返回值:无
(3) uint16_t readValue(uint8_t index)
描述:获取定向数据
参数:
index |
选择获取某一方向轴上的定向角度,0为X轴,1为Y轴,2为Z轴 |
返回值:整数,0~360
编程示例:
#include "WeELF328P.h" WeCompassSensor compass(PORT_A); void setup() { Serial.begin(115200); } void loop() { int16_t head_X; compass.update(); head_X = compass.readValue(0); Serial.print("Compass:"); Serial.println(head_X); delay(200); }