BTduino - Arduino - Bluetooth 1.7

Licença: Livre ‎Tamanho do arquivo: 1.05 MB
‎Classificação dos usuários: 0.0/5 - ‎0 ‎Votos

Sobre BTduino - Arduino - Bluetooth

BTduino 是利用手機藍芽裝置(Bluetooth)連接 Arduino 的應用程式。此程式現提供數字按鍵模式及遊戲控制器模。往後亦會加入PWM,各種感應器及按鍵配對等功能。使用者需連接藍芽接收裝置如HC06至Arduino。藍芽HC06連接Arduino的設置如下: 1. 藍芽VCC接Arduino 5v或3.3v (視乎所購買的裝置而定) 2. 藍芽GND接Arduino GND 3. 藍芽RXD接Arduino TX(Pin10) 4. 藍芽TXD接Arduino RX(Pin11) Arduino RX (Pino 11) conecta-se ao Bluethooth TX, Arduino TX (Pino 10) conecta-se ao Bluethooth RX

Arduino 設定 /* btduino2 - Terminal Mode - por David Chung */ #include

SoftwareSerial myBT(11, 10); const int ledPin = 13; String inCode = ""; boolean endCode = falso;

configuração do vazio() { Serial.start(9600); myBT.start(9600); pinMode(ledPin, OUTPUT); inCode.reserve(50); }

loop vazio() { se (myBT.disponível()) { char incomingChar = myBT.read(); se (incomingChar == ')'){ endCode = verdadeiro; } outra coisa { inCode += incomingChar; } }

se (endCode){ int strEnd = inCode.indexOf(')'); String myString = inCode.substring(0, strEnd);

Serial.print("Incoming : "); Serial.println(myString); se (myString == "on"){ digitalWrite(ledPin, HIGH); myBT.print ("LED On"); } se (myString == "off"){ digitalWrite(ledPin, LOW); myBT.print ("LED Off"); } inCode = ""; endCode = falso; } }

/* btduino2 - GamePad Mode - por David Chung */ #include

SoftwareSerial myBT(11, 10); const int ledPin = 13; int incomingByte = 0;

configuração do vazio() { Serial.start(9600); myBT.start(9600); pinMode(ledPin, OUTPUT); }

loop vazio() { se (myBT.disponível()) { incomingByte = myBT.read(); Serial.println(char(incomingByte)); se (incomingByte == 'L'){ digitalWrite(ledPin, HIGH); } se (incomingByte == 'R'){ digitalWrite(ledPin, LOW); } } }

/* Modo deslizante */ #include

SoftwareSerial myBT(11, 10); const int ledPin = 13; String inCode = "";

boolean endCode = falso;

configuração do vazio() { Serial.start(9600); myBT.start(9600); pinMode(ledPin, OUTPUT); inCode.reserve(30); }

loop vazio() { se (myBT.disponível()) { char incomingChar = myBT.read(); se (incomingChar == ')'){ endCode = verdadeiro; } outra coisa { inCode += incomingChar; } }

se (endCode){ ima1 = inCode.indexOf(''); ima2 = inCode.indexOf('', comíma1 + 1); String Rs = inCode.substring(0, címula1); String Gs = inCode.substring(comma1 + 1, címula2); String Bs = inCode.substring(comma2 + 1);

Serial.print("inCode = "); Serial.print(inCode); Serial.print(" R = "); Serial.print(Rs); Serial.print(" G = "); Serial.print(Gs); Serial.print(" B = "); Serial.println(Bs);

int R = Rs.toInt(); int G = Gs.toInt(); int B = Bs.toInt();

analógicoWrite (ledPin, R); inCode = ""; endCode = falso; } }

/* btduino2 - Modo de Orientação - por David Chung */ #include

SoftwareSerial myBT(11, 10); const int ledPin = 13; String inCode = ""; boolean endCode = falso;

configuração do vazio() { Serial.start(9600); myBT.start(9600); pinMode(ledPin, OUTPUT); inCode.reserve(30); }

loop vazio() { se (myBT.disponível()) { char incomingChar = myBT.read(); se (incomingChar == ')'){ endCode = verdadeiro; } outra coisa { inCode += incomingChar; } }

se (endCode){ ima1 = inCode.indexOf(''); ima2 = inCode.indexOf('', comíma1 + 1); String As = inCode.substring(0, comma1); String Ps = inCode.substring(comma1 + 1, címula2); String Rs = inCode.substring(comma2 + 1);

Serial.print("inCode = "); Serial.print(inCode); Serial.print(" Azimuth = "); Serial.print(As); Serial.print(" Pitch = "); Serial.print(Ps); Serial.print(" Roll = "); Serial.println(Rs);

int A = As.toInt(); int P = Ps.toInt(); int R = Rs.toInt();

inCode = ""; endCode = falso; } }