아크릴 영역: 100*75
오른쪽(빨강) - 5V
가운데(주황) - Din
왼쪽(검정) - GND
#include <SoftwareSerial.h>
#include "Adafruit_NeoPixel.h"
SoftwareSerial BTSerial(4, 5);
Adafruit_NeoPixel strip =
Adafruit_NeoPixel(3, 6, NEO_GRB + NEO_KHZ800);
char data;
int r;
int g;
int b;
unsigned long time_previous = 0;
void setup() {
BTSerial.begin(9600);
Serial.begin(9600);
strip.begin();
ran();
data = '0';
}
void loop() {
unsigned long time_current = millis();
if (BTSerial.available()) {
data = BTSerial.read();
Serial.write(data);
}
if (data == '0') {
if(time_current - time_previous >= 1000){
time_previous = time_current;
ran();
}
}
if (data == '1') {
for (int i = 0; i < 3; i++) {
strip.setPixelColor(i, 255, 0, 0);
strip.show();
}
}
if (data == '2') {
for (int i = 0; i < 3; i++) {
strip.setPixelColor(i, 0, 255, 0);
strip.show();
}
}
if (data == '3') {
for (int i = 0; i < 3; i++) {
strip.setPixelColor(i, 0, 0, 255);
strip.show();
}
}
if (data == '4') {
for (int i = 0; i < 3; i++) {
strip.setPixelColor(i, 255, 255, 255);
strip.show();
}
}
if (data == '5') {
for (int i = 0; i < 3; i++) {
strip.setPixelColor(i, 0, 0, 0);
strip.show();
}
}
}
void ran(){
r = random(0, 255);
g = random(0, 255);
b = random(0, 255);
for (int i = 0; i < 3; i++) {
strip.setPixelColor(i, strip.Color(r,g,b));
}
strip.show();
}
(주의)왼쪽 코드를 복사 붙여넣기 할 경우 오류가 발생할 수 있음.
아두이노로 보낼 데이터
앱에 표시될 아이콘
OK