|
我在做一个灵感来自于3D打印机的起重机,想用blinker控制电机和舵机,蓝牙ble接入,同样程序在uno上可以编译上传,但是在due上无法编译,我看论坛有人说是编程器的问题,换了编程器还是不行,迷……
代码如下:
#define BLINKER_BLE
#define ENA_one 3
#define in1_one 2
#define in2_one 4
#define ENA_two 5
#define in3_two 7
#define in4_two 8
#define ENA_three 6
#define in1_three 10
#define in2_three 11
#define ENA_four 9
#define in3_four 12
#define in4_four 13
#include <Blinker.h>
BlinkerButton Button1("btn-abc");
BlinkerButton Button2("btn-fic");
BlinkerButton Button3("btn-01g");
BlinkerButton Button4("btn-8xa");
BlinkerButton Button5("btn-d91");
BlinkerButton Button6("btn-oy9");
BlinkerButton Button7("btn-574");
BlinkerButton Button8("btn-o2j");
BlinkerButton Button9("btn-bf1");
BlinkerButton Button10("btn-or9");
BlinkerNumber Number1("num-abc");
int counter = 0;
int sudu=100;
int suduxie=120;
int suduweitiao=111;
int suduxieweitiao=131;
void forward();
void backward();
void _stop();
//void fanzhuan();
void dianjichushihua();
void nishizheng();
void shunshizheng();
void left();
void right();
void zuoshang();
void youxia();
void zuoxia();
void youshang();
void button1_callback(const String & state);
void button2_callback(const String & state);
void button3_callback(const String & state);
void button4_callback(const String & state);
void button5_callback(const String & state);
void button6_callback(const String & state);
void button7_callback(const String & state);
void button8_callback(const String & state);
void button9_callback(const String & state);
void button10_callback(const String & state);
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
void setup()
{
Serial.begin(9600);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
Blinker.begin(A1,A0);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
Button6.attach(button6_callback);
Button7.attach(button7_callback);
Button8.attach(button8_callback);
Button9.attach(button9_callback);
Button10.attach(button10_callback);
dianjichushihua();
}
void loop()
{
Blinker.run();
}
//………………………………………………函数定义……………………………………
void dianjichushihua()
{
pinMode(ENA_one,OUTPUT);
pinMode(in1_one,OUTPUT);
pinMode(in2_one,OUTPUT);
pinMode(ENA_two,OUTPUT);
pinMode(in3_two,OUTPUT);
pinMode(in4_two,OUTPUT);
//pinMode(xinhao_two,INPUT);
pinMode(ENA_three,OUTPUT);
pinMode(in1_three,OUTPUT);
pinMode(in2_three,OUTPUT);
//pinMode(xinhao_three,INPUT);
pinMode(ENA_four,OUTPUT);
pinMode(in3_four,OUTPUT);
pinMode(in4_four,OUTPUT);
//pinMode(xinhao_four,INPUT);
}
void _stop()
{
analogWrite(ENA_one,0);
digitalWrite(in1_one,HIGH);
digitalWrite(in2_one,LOW);
analogWrite(ENA_two,0);
digitalWrite(in3_two,HIGH);
digitalWrite(in4_two,LOW);
analogWrite(ENA_three,0);
digitalWrite(in1_three,HIGH);
digitalWrite(in2_three,LOW);
analogWrite(ENA_four,0);
digitalWrite(in3_four,HIGH);
digitalWrite(in4_four,LOW);
}
/*
void fanzhuan()
{
analogWrite(ENA,sudu);
}
*/
void forward()
{
analogWrite(ENA_one,suduweitiao);
digitalWrite(in1_one,LOW);
digitalWrite(in2_one,HIGH);
analogWrite(ENA_two,suduweitiao);
digitalWrite(in3_two,LOW);
digitalWrite(in4_two,HIGH);
analogWrite(ENA_three,sudu);
digitalWrite(in1_three,HIGH);
digitalWrite(in2_three,LOW);
analogWrite(ENA_four,sudu);
digitalWrite(in3_four,HIGH);
digitalWrite(in4_four,LOW);
}
void nishizheng()
{
analogWrite(ENA_one,suduweitiao);
digitalWrite(in1_one,LOW);
digitalWrite(in2_one,HIGH);
analogWrite(ENA_two,suduweitiao);
digitalWrite(in3_two,LOW);
digitalWrite(in4_two,HIGH);
analogWrite(ENA_three,sudu);
digitalWrite(in1_three,LOW);
digitalWrite(in2_three,HIGH);
analogWrite(ENA_four,sudu);
digitalWrite(in3_four,LOW);
digitalWrite(in4_four,HIGH);
}
void shunshizheng()
{
analogWrite(ENA_one,suduweitiao);
digitalWrite(in1_one,HIGH);
digitalWrite(in2_one,LOW);
analogWrite(ENA_two,suduweitiao);
digitalWrite(in3_two,HIGH);
digitalWrite(in4_two,LOW);
analogWrite(ENA_three,sudu);
digitalWrite(in1_three,HIGH);
digitalWrite(in2_three,LOW);
analogWrite(ENA_four,sudu);
digitalWrite(in3_four,HIGH);
digitalWrite(in4_four,LOW);
}
void backward()
{
analogWrite(ENA_one,suduweitiao);
digitalWrite(in1_one,HIGH);
digitalWrite(in2_one,LOW);
analogWrite(ENA_two,suduweitiao);
digitalWrite(in3_two,HIGH);
digitalWrite(in4_two,LOW);
analogWrite(ENA_three,sudu);
digitalWrite(in1_three,LOW);
digitalWrite(in2_three,HIGH);
analogWrite(ENA_four,sudu);
digitalWrite(in3_four,LOW);
digitalWrite(in4_four,HIGH);
}
void left()
{
analogWrite(ENA_one,suduweitiao);
digitalWrite(in1_one,LOW);
digitalWrite(in2_one,HIGH);
analogWrite(ENA_two,suduweitiao);
digitalWrite(in3_two,HIGH);
digitalWrite(in4_two,LOW);
analogWrite(ENA_three,sudu);
digitalWrite(in1_three,LOW);
digitalWrite(in2_three,HIGH);
analogWrite(ENA_four,sudu);
digitalWrite(in3_four,HIGH);
digitalWrite(in4_four,LOW);
}
void right()
{
analogWrite(ENA_one,suduweitiao);
digitalWrite(in1_one,HIGH);
digitalWrite(in2_one,LOW);
analogWrite(ENA_two,suduweitiao);
digitalWrite(in3_two,LOW);
digitalWrite(in4_two,HIGH);
analogWrite(ENA_three,sudu);
digitalWrite(in1_three,HIGH);
digitalWrite(in2_three,LOW);
analogWrite(ENA_four,sudu);
digitalWrite(in3_four,LOW);
digitalWrite(in4_four,HIGH);
}
void zuoshang()
{
analogWrite(ENA_one,suduxieweitiao);
digitalWrite(in1_one,LOW);
digitalWrite(in2_one,HIGH);
analogWrite(ENA_two,0);
digitalWrite(in3_two,LOW);
digitalWrite(in4_two,HIGH);
analogWrite(ENA_three,0);
digitalWrite(in1_three,HIGH);
digitalWrite(in2_three,LOW);
analogWrite(ENA_four,suduxie);
digitalWrite(in3_four,HIGH);
digitalWrite(in4_four,LOW);
}
void youxia()
{
analogWrite(ENA_one,suduxieweitiao);
digitalWrite(in1_one,HIGH);
digitalWrite(in2_one,LOW);
analogWrite(ENA_two,0);
digitalWrite(in3_two,LOW);
digitalWrite(in4_two,HIGH);
analogWrite(ENA_three,0);
digitalWrite(in1_three,HIGH);
digitalWrite(in2_three,LOW);
analogWrite(ENA_four,suduxie);
digitalWrite(in3_four,LOW);
digitalWrite(in4_four,HIGH);
}
void youshang()
{
analogWrite(ENA_one,0);
digitalWrite(in1_one,LOW);
digitalWrite(in2_one,HIGH);
analogWrite(ENA_two,suduxieweitiao);
digitalWrite(in3_two,LOW);
digitalWrite(in4_two,HIGH);
analogWrite(ENA_three,suduxie);
digitalWrite(in1_three,HIGH);
digitalWrite(in2_three,LOW);
analogWrite(ENA_four,0);
digitalWrite(in3_four,HIGH);
digitalWrite(in4_four,LOW);
}
void zuoxia()
{
analogWrite(ENA_one,0);
digitalWrite(in1_one,LOW);
digitalWrite(in2_one,HIGH);
analogWrite(ENA_two,suduxieweitiao);
digitalWrite(in3_two,HIGH);
digitalWrite(in4_two,LOW);
analogWrite(ENA_three,suduxie);
digitalWrite(in1_three,LOW);
digitalWrite(in2_three,HIGH);
analogWrite(ENA_four,0);
digitalWrite(in3_four,HIGH);
digitalWrite(in4_four,LOW);
}
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
//digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
//Button1.icon("icon_1");
Button1.color("#FFFFFF");
Button1.text("前进");
// Button1.text("Your button name", "describe");
Button1.print();
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//电机程序
forward();
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
//Button1.icon("icon_1");
Button1.color("#00FF00");
Button1.text("前进");
// Button1.text("Your button name", "describe");
Button1.print();
_stop();
}
else
{
Button1.print();
}
}
void button2_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
Button2.text("后退");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//电机程序
backward();
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
Button2.print();
_stop();
}
else
{
Button2.print();
}
}
void button3_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
Button3.text("向左");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//电机程序
left();
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
Button3.print();
_stop();
}
else
{
Button3.print();
}
}
void button4_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
Button4.text("向右");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//电机程序
right();
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
Button4.print();
_stop();
}
else
{
Button4.print();
}
}
void button5_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
Button5.text("左上");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//电机程序
zuoshang();
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
Button5.print();
_stop();
}
else
{
Button5.print();
}
}
void button6_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
Button6.text("右上");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//电机程序
youshang();
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
Button6.print();
_stop();
}
else
{
Button6.print();
}
}
void button7_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
Button7.text("左下");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//电机程序
zuoxia();
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
Button7.print();
_stop();
}
else
{
Button7.print();
}
}
void button8_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
Button8.text("右下");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//电机程序
youxia();
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
Button8.print();
_stop();
}
else
{
Button8.print();
}
}
void button9_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
Button9.text("顺时针");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//电机程序
shunshizheng();
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
Button9.print();
_stop();
}
else
{
Button9.print();
}
}
void button10_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
Button10.text("逆时针");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//电机程序
nishizheng();
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
Button10.print();
_stop();
}
else
{
Button10.print();
}
}
|
-
|