本帖最後由 我不是小妹 於 2015-11-14 14:56 編輯
小弟我的藍芽是HC-06馬達是L298N的DC直流馬達.......
APP程式是用APP Inventor 2寫的
請各位看一下哪邊有錯......編譯成功然後燒進去然後車子都不會動.....
#include <Wire.h>
#include <SoftwareSerial.h>
SoftwareSerial I2CBT(10,11);
const int ENA = 5;
const int In1 = 6;
const int In2 = 7;
const int In3 = 8;
const int In4 = 9;
const int ENB = 13;
void setup() {
Serial.begin(9600); //Arduino起始鮑率:9600
pinMode(In1,OUTPUT);
pinMode(In2,OUTPUT);
pinMode(In3,OUTPUT);
pinMode(In4,OUTPUT);
}
void motorStop()
{
analogWrite(ENA,200);
analogWrite(ENB,200);
digitalWrite(In1,LOW);
digitalWrite(In2,LOW);
digitalWrite(In3,LOW);
digitalWrite(In4,LOW);
}
void forward(){
analogWrite(ENA,200);
analogWrite(ENB,200);
digitalWrite(In1,HIGH);
digitalWrite(In2,LOW);
digitalWrite(In3,HIGH);
digitalWrite(In4,LOW);
}
void backward(){
analogWrite(ENA,200);
analogWrite(ENB,200);
digitalWrite(In1,LOW);
digitalWrite(In2,HIGH);
digitalWrite(In3,LOW);
digitalWrite(In4,HIGH);
}
void loop() {
char val = Serial.read();
Serial.write(val);
if (-1 != val) {
if ('f' == val)
forward();
else if ('b' == val)
backward();
else if ('s' == val)
motorStop();
delay(500);
}
else
{
//stop();
delay(500);
}
}-----------------------------------------
APP的地方
|