BASIC4MCU | 질문게시판 | 아두이노 인터럽트 질문있습니다.
페이지 정보
작성자 띵꽁 작성일2022-05-22 18:50 조회352회 댓글1건본문
현재 블루투스를 이용한 네오픽셀 관련 작품을 준비중입니다.
사용중인 아두이노 모델은 우노모델입니다.
질문드리고싶은것이 기존에는 온도에 따른 색표현을 하다가 블루투스연결후 색을 지정하면 블루투스 명령을 우선으로 처리하게하고싶은데
어떤식으로 인터럽트를 사용해야할지 모르겠습니다.
도와주십시요....ㅠㅠ
현재까지 제가 작업한 아두이노 코딩입니다.
#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>
#define LED_PIN 6
#define LED_COUNT 16
#include <avr/power.h>
#define BRIGHTNESS 255
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
int delayval=20;
SoftwareSerial bluetooth(2,3);
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 7
#define DHYTPYE DHT11
hd44780_I2Cexp lcd;
DHT dht (DHTPIN, DHYTPYE);
void setup() {
strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show();
bluetooth.begin(9600);
lcd.begin(16, 2);
dht.begin();
Serial.begin(9600);
}
byte r = 0, g = 0, b = 0;
void loop() {
float humi, temp;
temp = dht.readTemperature();
humi = dht.readHumidity();
if(isnan(humi) || isnan(temp)){
Serial.println("Failed to read the DHT sensor!");
return;
}
lcd.clear ();
lcd.setCursor (0, 0);
lcd.print("temp: ");
lcd.print(temp);
lcd.setCursor (0, 1);
lcd.print("humi: ");
lcd.print (humi);
delay(300);
if(humi<10){
colorWipe(strip.Color(0,0,255),50);
}
else if((humi>=10)&&(humi<20)){
colorWipe(strip.Color(29,219,22),50);
}
else if((humi>=20)&&(humi<25)){
colorWipe(strip.Color(255,228,0),50);
}
else if((humi>=25)&&(humi<30)){
colorWipe(strip.Color(255,50,0),50);
}
else{
colorWipe(strip.Color(255,20,0),50);
}
if(bluetooth.available()>2){
r = bluetooth.read();
g = bluetooth.read();
b = bluetooth.read();
bluetooth.flush();
for(int i=LED_COUNT;i>=0; i--){
strip.setPixelColor(i, strip.Color(0,0,0));
strip.show();
delay(delayval);
}
delay(delayval);
for(int i=0; i<LED_COUNT; i++){
strip.setPixelColor(i, strip.Color(r,g,b));
strip.show();
delay(delayval);
}
}
}
void colorWipe(uint32_t c, uint8_t wait){
for(uint16_t i=0; i<strip.numPixels(); i++){
strip.setPixelColor(i,c);
strip.show();
delay(wait);
}
}
댓글 1
조회수 352master님의 댓글
master 작성일
같은 질문이 또 올라왔 군요
온도에 따른 색표현을 한다면 불루투스는 무시되고 온도에 따른 색표현만 반복됩니다.
온도 측정은 1초 이내로 매번 실행되고
불루투스는 1회 뿐이기 때문이죠