아두이노 - NEO LED BT모드

자료실

아두이노 - NEO LED BT모드

소프트웨어과 1 20,833 2022.06.03 11:08

#include <SoftwareSerial.h>        // 소프트웨어 시리얼 라이브러리를 포함

#include <Adafruit_NeoPixel.h>   // 네오픽셀 라이브러리를 포함

#define PIN 7

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(2, PIN, NEO_GRB + NEO_KHZ800);

SoftwareSerial bluetooth(2, 3);    // 디지털 2,3번 핀을 시리얼 통신 핀으로 설정

void setup() {

  pixels.begin(); 

  pixels.show();

  bluetooth.begin(9600);

}

byte r = 0, g = 0, b = 0;

void loop() {

  if (bluetooth.available() > 2) {       // 만약 2개가 넘는 데이터를 받는다면

    r = bluetooth.read();                    // r, g, b에 각각의 데이터를 대입

    g = bluetooth.read();

    b = bluetooth.read();

    bluetooth.flush();                         // 데이터가 전송완료될 때까지 대기

    pixels.setPixelColor(0, pixels.Color(r, g, b));     // 1번째 네오픽셀 설정

    pixels.setPixelColor(1, pixels.Color(r, g, b));     // 2번째 네오픽셀 설정

    pixels.show();

  }

}

Comments

소프트웨어과 2022.06.03 11:16
BT없이 단순 LED켜기

#include <Adafruit_NeoPixel.h>
#define PIN 7
#define LEDNUM 2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDNUM, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
}
void loop() {
  strip.begin();
  strip.show();
  strip.setPixelColor(0, 255, 0,0);
  strip.setPixelColor(1, 0, 0, 255);
  delay(4000);
  strip.begin();
  strip.show();
  strip.setPixelColor(0, 0, 0, 255);
  strip.setPixelColor(1, 0, 0, 255);
  delay(4000);
  strip.begin();
  strip.show();
  strip.setPixelColor(0, 0,100, 0);
  strip.setPixelColor(1, 0, 255, 255);
  delay(4000);
  strip.begin();
  strip.show();
  strip.setPixelColor(0, 255, 255, 0);
  strip.setPixelColor(1, 0, 100, 50);
  delay(4000);
  strip.begin();
  strip.show();
  strip.setPixelColor(0, 255, 255, 255);
  strip.setPixelColor(1, 100, 255, 0);
  delay(4000);
  strip.begin();
  strip.show();
  strip.setPixelColor(0, 255, 255, 255);
  strip.setPixelColor(1, 255, 255, 255);
  delay(4000);
}
Category
반응형 구글광고 등
State
  • 현재 접속자 48 명
  • 오늘 방문자 3,185 명
  • 어제 방문자 3,392 명
  • 최대 방문자 3,491 명
  • 전체 방문자 527,108 명
  • 전체 게시물 6,916 개
  • 전체 댓글수 132 개
  • 전체 회원수 31 명
Facebook Twitter GooglePlus KakaoStory NaverBand