#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
#define PIN 6
#define NUMPIXELS 6
SoftwareSerial BT(11, 10); // 傳送, 接收 ,藍牙模組通訊用
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
char val; //暫存從藍牙讀取到的資料
void setup()
{
BT.begin(9600); //啟動和「HC-06」的序列連線
Serial.begin(9600); //啟動和「電腦」的序列連線
Serial.println("Enter AT commands:");
pixels.begin();
pixels.show();
}
void loop()
{
if (BT.available()){ //如果從藍牙傳送資料來
val = BT.read(); //讀取資料
Serial.write(val);
if(val=='o'){ //這裡要看你在AppInventor程式傳遞什麼字元
colorWipe(pixels.Color(255,255,255), 50); // 設定要什麼顏色的燈
}else if(val=='c'){ //這裡要看你在AppInventor程式傳遞什麼字元
colorWipe(pixels.Color(0, 0, 0), 50); //close // 設定要什麼顏色的燈
}else if(val=='s'){ //這裡要看你在AppInventor程式傳遞什麼字元
colorWipe(pixels.Color(255, 106, 0), 50); //睡眠燈的RGB
}
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, c);
pixels.show();
delay(wait);
}
}