BASIC4MCU | 질문게시판 | 답변 : 센서나 블루투스에서 조건문이 실행이 느립니다.
페이지 정보
작성자 master 작성일2024-05-03 21:09 조회388회 댓글0건본문
#include <SoftwareSerial.h>
SoftwareSerial btSerial(11,12);
#include <Adafruit_NeoPixel.h>
#define LED_PIN 4
#define LED_COUNT 20
Adafruit_NeoPixel pixels=Adafruit_NeoPixel(LED_COUNT,LED_PIN,NEO_GRBW+NEO_KHZ800);
//
int c,red=0,green=0,blue=0;
//
void setup(){
btSerial.begin(9600);
pinMode(7,OUTPUT); pinMode(8,OUTPUT); pinMode(9,OUTPUT); pinMode(10,OUTPUT);
pixels.begin(); pixels.show();
}
//
void loop(){
analogWrite(3,0); analogWrite(5,0); analogWrite(6,0);
for(int i=0;i<LED_COUNT;i++){ pixels.setPixelColor(i,0,0,0,0); } pixels.show();
//
if(btSerial.available()){
c=btSerial.read();
if(c=='A'){
analogWrite(5,250); analogWrite(3,30);
for(int i=0; i<LED_COUNT; i++){ pixels.setPixelColor(i,210,50,0,0); } pixels.show();
}
else if(c=='B'){
analogWrite(3,250);
for(int i=0;i<LED_COUNT;i++){ pixels.setPixelColor(i,50,250,0,0); } pixels.show();
}
else if(c=='C'){
for(int i=0;i<LED_COUNT;i++){ pixels.setPixelColor(i,0,0,0,250); } pixels.show();
}
else if(c=='D'){
for(int i=0;i<20;i++){ pixels.setPixelColor(i,200-i*10,0+i*10,0,0); pixels.show(); delay(100); }
for(int i=0;i<20;i++){ pixels.setPixelColor(i,0,200-i*10,0+i*10,0); pixels.show(); delay(100); }
for(int i=0;i<20;i++){ pixels.setPixelColor(i,0+i*10,0,200-i*10,0); pixels.show(); delay(100); }
}
}
}
댓글 0
조회수 388등록된 댓글이 없습니다.