blinker简易机器人
本帖最后由 lwq1947 于 2020-11-11 16:16 编辑最近有空就利用家中已淘汰的摄象头作为机器人的头部,用大筒的饮料瓶去掉瓶颈部分作为机器人的身躯.内部装上从旧玩具拆下的驱动部件作为机器人的行走机构.主控系统为NodeMcu开发板.通过它来控制两个SG90舵机来驱动机器人的手臂运动.机器人的内部还配有语音芯片ISD1420可以让机器人会说你好,再见和唱歌.
电源部分利用了破损的充电宝中的3.6V锂电池,再通过2a升压板产生5V供电电源,由于驱动电机为玩具130电机,所以即使使用3,6V锂电池供电,电机转速也太快,所以再通过LM25965降压模块来固定在1.25V,以使电机可以稳定运转.
手机通过blinker来控制机器人各种动作.同时手机采用分屏模式使得摄像头显示界面在blinker界面之上,这样就可通过观察摄像头来控制机器人运动路线.同时由于该摄像头本身具有双向语音对讲功能可使控制者与外界能直接进行交流.
blinker控制界面中第一排有两个前进按键.单独按压一个为向左或向右旋转,同时按下时机器人会向前运动并且双臂也会前后摆动如人行走的姿态.两按键之间还有电压表以显示电池电压高低,当电压降至3V时就应通过TP4056来给锂电池充电.
第二排有从左至右共有三个按键,当第一个按压后,机器人的双手抬起挥动并说"你好",当第二个按压后,机器人开使舞动手臂,时而左转时而右转类似舞者,同时开唱"祝你天天快乐"歌(将生日歌中的"生日"换成"天天").当第三个按压后,机器人右手举起挥动并说"再见".当然这些语音都是提前录制在ISD1420芯片上的.
程序如下:
#define BLINKER_WIFI
#include <Blinker.h>
#include <Servo.h>
Servo lservo;
Servo rservo;
char auth[]="*******";
char ssid[]="*******";
char pswd[]="*******";
BlinkerButton Button0("wu");
BlinkerButton Button1("he");
BlinkerButton Button2("by");
BlinkerButton Button3("lf");
BlinkerButton Button4("rf");
BlinkerNumber Battery("dy");
int val=0;
int x=0;
int y=0;
int z=0;
int r=0;
int l=0;
int pos=45;
int dy_read=0;
void button0_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_TAP)
{
Button0.icon("fal fa-dove");//fa-lightbulb
Button0.color("#00FF00");
Button0.text("开");
x=1;
Button0.print("on");
}
}
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_TAP)
{
Button1.icon("fal fa-dove");//fa-lightbulb
Button1.color("#00FF00");
Button1.text("开");
y=1;
Button1.print("on");
}
}
void button2_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_TAP)
{
Button2.icon("fal fa-dove");//fa-lightbulb
Button2.color("#00FF00");
Button2.text("开");
z=1;
Button2.print("on");
}
}
void button3_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_PRESSED)
{
Button3.icon("fas fa-arrow-alt-up");//fa-lightbulb
Button3.color("#00FF00");
Button3.text("开");
digitalWrite(13, HIGH);
r=1;
Button3.print("on");
}
else if(state == BLINKER_CMD_BUTTON_RELEASED)
{
Button3.icon("fal fa-arrow-alt-up");
Button3.color("#0000FF");
Button3.text("关");
digitalWrite(13, LOW);
r=0;
Button3.print("off");
}
}
void button4_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_PRESSED)
{
Button4.icon("fas fa-arrow-alt-up");//fa-lightbulb
Button4.color("#00FF00");
Button4.text("开");
digitalWrite(12, HIGH);
l=1;
Button4.print("on");
}
else if(state == BLINKER_CMD_BUTTON_RELEASED)
{
Button4.icon("fal fa-arrow-alt-up");
Button4.color("#0000FF");
Button4.text("关");
digitalWrite(12, LOW);
l=0;
Button4.print("off");
}
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print(BlinkerTime);
Blinker.print("millis", BlinkerTime);
}
void heartbeat()
{
Battery.print(dy_read);
}
void setup()
{
lservo.attach(14);
rservo.attach(15);
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
pinMode(A0,INPUT);
pinMode(2, OUTPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(16, OUTPUT);
digitalWrite(2, LOW);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(16, HIGH);
Blinker.begin(auth, ssid, pswd);
Blinker.attachHeartbeat(heartbeat);
Button0.attach(button0_callback);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
Blinker.attachData(dataRead);
}
void loop()
{
Blinker.run();
val=analogRead(A0);
dy_read=val*4200/1014;
Blinker.delay(100);
if(x==1)
{ digitalWrite(2, HIGH);
digitalWrite(5, HIGH);
digitalWrite(16, LOW);
for (pos = 45; pos <= 90; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 90; pos >= 45; pos -= 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 45; pos <= 90; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 90; pos >= 45; pos -= 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
for (pos = 45; pos <= 90; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 90; pos >= 45; pos -= 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 45; pos <= 90; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 90; pos >= 45; pos -= 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
}
for (pos = 45; pos <= 90; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
digitalWrite(12, HIGH);
for (pos =90; pos <= 180; pos += 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos = 180; pos >= 135; pos -= 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos =135; pos <= 180; pos += 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos = 180; pos >= 135; pos -= 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos =135; pos <= 180; pos += 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos = 180; pos >= 135; pos -= 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos =135; pos <= 180; pos += 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos = 180; pos >= 135; pos -= 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
digitalWrite(12, LOW);
delay(1000);
digitalWrite(13, HIGH);
for (pos = 135; pos >= 0; pos -= 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos =0; pos <= 45; pos += 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos = 45; pos >= 0; pos -= 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos =0; pos <= 45; pos += 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos = 45; pos >= 0; pos -= 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos =0; pos <= 45; pos += 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos = 45; pos >= 0; pos -= 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos =0; pos <= 45; pos += 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
for (pos = 45; pos >= 0; pos -= 1) {
rservo.write(pos);
lservo.write(pos);
delay(10);
}
digitalWrite(13, LOW);
delay(1000);
for (pos = 0; pos <= 135; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 135; pos >= 90; pos -= 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 90; pos <= 135; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 135; pos >= 90; pos -= 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 90; pos <= 135; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 135; pos >= 90; pos -= 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 90; pos <= 135; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 135; pos >= 90; pos -= 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
delay(1000);
for (pos = 90; pos >= 45; pos -= 1){
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
digitalWrite(16, HIGH);
digitalWrite(5, LOW);
digitalWrite(2, LOW);
x=0;
}
if(y==1)
{ digitalWrite(2, HIGH);
digitalWrite(16, LOW);
for (pos = 45; pos <= 135; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(5);
}
for (pos = 135; pos >= 115; pos -= 1) {
rservo.write(pos);
delay(10);
}
for (pos = 115; pos <= 135; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 135; pos >= 115; pos -= 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 115; pos <= 135; pos += 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(10);
}
for (pos = 135; pos >= 45; pos -= 1) {
rservo.write(pos);
lservo.write(180-pos);
delay(5);
}
y=0;
digitalWrite(2, LOW);
digitalWrite(16, HIGH);
}
if(z==1)
{ digitalWrite(2, HIGH);
digitalWrite(4, HIGH);
digitalWrite(16, LOW);
for (pos = 45; pos <= 180; pos += 1) {
rservo.write(pos);
delay(5);
}
for (pos = 180; pos >= 160; pos -= 1) {
rservo.write(pos);
delay(10);
}
for (pos = 160; pos <= 180; pos += 1) {
rservo.write(pos);
delay(10);
}
for (pos = 180; pos >= 160; pos -= 1) {
rservo.write(pos);
delay(10);
}
for (pos = 160; pos <= 180; pos += 1) {
rservo.write(pos);
delay(10);
}
for (pos = 180; pos >= 45; pos -= 1) {
rservo.write(pos);
delay(5);
}
z=0;
digitalWrite(2, LOW);
digitalWrite(4, LOW);
digitalWrite(16, HIGH);
}
if((r==1)&&(l==1))
{
digitalWrite(2, HIGH);
for (pos = 0; pos <= 90; pos += 1) {
rservo.write(pos);
lservo.write(pos+90);
delay(10);
}
for (pos = 90; pos >= 0; pos -= 1) {
rservo.write(pos);
lservo.write(pos+90);
delay(10);
}
}
else
{
rservo.write(45);
lservo.write(135);
digitalWrite(2, LOW);
}
}
不错,机器人能出家门吗? tnn0220 发表于 2020-11-20 10:09
不错,机器人能出家门吗?
这个不行,若机器人里配备4G装置方可.
页:
[1]