BTduino - Arduino - Bluetooth 1.7

Lesen: Percuma ‎Saiz fail: 1.05 MB
‎Penarafan Pengguna: 0.0/5 - ‎0 ‎Undi

Tentang 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 (Pin 11) menyambung ke Bluethooth TX, Arduino TX (Pin 10) menyambung ke Bluethooth RX

Arduino 設定 /* btduino2 - Mod Terminal - oleh David Chung */ #include

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

persediaan tidak sah() { Serial.start(9600); myBT.start(9600); pinMode (ledPin, OUTPUT); inCode.reserve(50); }

gelung tidak sah() { jika (myBT.tersedia()) { char masukChar = myBT.read(); jika (masukChar == ')'){ endCode = benar; } lain { inCode += incomingChar; } }

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

Serial.print("Masuk : "); Serial.println (myString); jika(myString == "on"){ digitalWrite (ledPin, TINGGI); myBT.print("LED On"); } jika(myString == "mati"){ digitalWrite (ledPin, LOW); myBT.print("LED Off"); } inCode = ""; endCode = palsu; } }

/* btduino2 - Mod GamePad - oleh David Chung */ #include

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

persediaan tidak sah() { Serial.start(9600); myBT.start(9600); pinMode (ledPin, OUTPUT); }

gelung tidak sah() { jika (myBT.tersedia()) { incomingByte = myBT.read(); Serial.println (char (incomingByte)); jika (masukByte == 'L'){ digitalWrite (ledPin, TINGGI); } jika (masukByte == 'R'){ digitalWrite (ledPin, LOW); } } }

/* Mod Gelangsar */ #include

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

boolean endCode = palsu;

persediaan tidak sah() { Serial.start(9600); myBT.start(9600); pinMode (ledPin, OUTPUT); inCode.reserve(30); }

gelung tidak sah() { jika (myBT.tersedia()) { char masukChar = myBT.read(); jika (masukChar == ')'){ endCode = benar; } lain { inCode += incomingChar; } }

jika (endCode){ int comma1 = inCode.indexOf(','); int comma2 = inCode.indexOf(',', comma1 + 1); Rentetan Rs = inCode.substring (0, koma1); Rentetan Gs = inCode.substring (comma1 + 1, koma2); Rentetan 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);

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

analogWrite (ledPin, R); inCode = ""; endCode = palsu; } }

/* btduino2 - Mod Orientasi - oleh David Chung */ #include

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

persediaan tidak sah() { Serial.start(9600); myBT.start(9600); pinMode (ledPin, OUTPUT); inCode.reserve(30); }

gelung tidak sah() { jika (myBT.tersedia()) { char masukChar = myBT.read(); jika (masukChar == ')'){ endCode = benar; } lain { inCode += incomingChar; } }

jika (endCode){ int comma1 = inCode.indexOf(','); int comma2 = inCode.indexOf(',', comma1 + 1); Rentetan Seperti = inCode.substring(0, koma1); Rentetan Ps = inCode.substring (comma1 + 1, comma2); Rentetan 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(); r = Rs.toInt();

inCode = ""; endCode = palsu; } }