|
求助Blinker使用,我按照官网的相关指南配置,写好代码后,蓝牙显示已连接,但是按下按键后无反应,RGB色盘转动也无反应,求助
手机是IOS,附上配置图及代码,蓝牙模块是就直接插上就用了,没有配置过。
蓝牙模块是JDT-18,板子是Arduino Uno.接线没有问题,代码部分除了Blinker相关的也实验过没有问题。
#define BLINKER_PRINT Serial
#define BLINKER_BLE
#include <Blinker.h>
#include <FastLED.h>
#define RGB_1 "RGBKey"
BlinkerRGB RGB1(RGB_1);
#define BUTTON_1 "ButtonKey"
BlinkerButton Button1(BUTTON_1);
//The amount of LEDs in the setup
#define NUM_LEDS 64
//The pin that controls the LEDs
#define LED_PIN 6
//The pin that we read volume sensor values from
#define ANALOG_READ 0
//Led array
CRGB leds[NUM_LEDS];
// LED Mode1/Music LED--LED Mode2/Color LED
int LED_MODE = 1;
// LED TYPE
#define LED_TYPE WS2812
// RGB TYPE
#define COLOR_ORDER GRB
// when you use the MusicLED as a Color LED
CRGB LEDColor(0,0,0);
uint8_t Bright = 255;
//LED LINE
int LEDLINE[8][8]{
{0,1,2,3,4,5,6,7},
{15,14,13,12,11,10,9,8},
{16,17,18,19,20,21,22,23},
{31,30,29,28,27,26,25,24},
{32,33,34,35,36,37,38,39},
{47,46,45,44,43,42,41,40},
{48,49,50,51,52,53,54,55},
{63,62,61,60,59,58,57,56}
};
// A counter when using LEDLINE
int counter=0;
//color plate
int ledc[45][3]{
{0,0,255},{17,0,238},{34,0,221},{51,0,204},{68,0,187},
{85,0,170},{102,0,153},{119,0,136},{136,0,119},{153,0,102},
{170,0,85},{187,0,68},{204,0,51},{221,0,34},{238,0,17},
{255,0,0},{238,17,0},{221,34,0},{204,0,51},{187,0,68},
{170,85,0},{153,102,0},{136,119,0},{119,136,0},{102,153,0},
{85,170,0},{68,187,0},{51,204,0},{34,221,0},{17,238,0},
{0,255,0},{0,238,17},{0,221,34},{0,204,51},{0,187,68},
{0,170,85},{0,153,102},{0,136,119},{0,119,136},{0,102,153},
{0,85,170},{0,68,187},{0,51,204},{0,34,221},{0,17,238}
};
//color plate counter
int plate=0;
void LOWMODE();
void MIDMODE();
void HIGHMODE();
void visualize_music( int VOLUME );
// rgb1_callback
void rgb1_callback(uint8_t r_value, uint8_t g_value, uint8_t b_value, uint8_t bright_value)
{
// change the color of strip by your set on Blinker
LEDColor.r = r_value;
LEDColor.g = g_value;
LEDColor.b = b_value;
Bright = bright_value;
fill_solid(leds,NUM_LEDS,LEDColor);
FastLED.show();
}
void button1_callback(const String & state) {
if(LED_MODE == 1)
{
LEDColor.r = 255;
LEDColor.g = 255;
LEDColor.b = 255;
Bright = 0;
fill_solid(leds,NUM_LEDS,LEDColor);
BLINKER_LOG("MUSIC LED: ","OFF");
LED_MODE = 2;
}
else if(LED_MODE == 2)
{
LED_MODE = 1;
}
FastLED.show();
}
void setup() {
//Set all lights to make sure all are working as expected
Blinker.begin();
Serial.begin(9600);
LEDS.addLeds<LED_TYPE,LED_PIN,GRB>(leds,NUM_LEDS);
int i;
for( i=0;i<64;i++){
leds[i]=CRGB(0,127,128);
}
FastLED.setBrightness(100);
FastLED.show();
delay(1000);
//Initial values
// Blinker.begin();
//attach the RGB1 SlidersRGB
RGB1.attach(rgb1_callback);
Button1.attach(button1_callback);
}
void loop() {
Blinker.run();
if(LED_MODE == 1){
visualize_music(analogRead(0));
}
delay(1); // delay in between reads for stability
}
void LOWMODE(){
FastLED.clear();
for(int m=0;m<1;m++){
for(int j=0;j<8;j++){
leds[LEDLINE[m][j]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
}
}
leds[LEDLINE[1][(1+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[2][(1+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[3][(1+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[1][(2+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[2][(2+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[1][(3+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[1][(4+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[2][(4+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[2][(4+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[1][(6+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[2][(6+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[1][(7+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
FastLED.show();
delay(150);
counter++;
if(counter>=8){
counter-=8;
}
plate++;
if(plate>=45){
plate-=45;
}
}
void MIDMODE(){
FastLED.clear();
for(int m=0;m<3;m++){
for(int j=0;j<8;j++){
leds[LEDLINE[m][j]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
}
}
leds[LEDLINE[3][(1+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[4][(1+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[5][(1+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[3][(2+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[4][(2+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[3][(3+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[3][(4+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[4][(4+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[4][(4+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[3][(6+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[4][(6+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[3][(7+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
FastLED.show();
delay(150);
counter++;
if(counter>=8){
counter-=8;
}
plate++;
if(plate>=45){
plate-=45;
}
}
void HIGHMODE(){
FastLED.clear();
for(int m=0;m<5;m++){
for(int j=0;j<8;j++){
leds[LEDLINE[m][j]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
}
}
leds[LEDLINE[5][(1+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[6][(1+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[7][(1+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[5][(2+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[6][(2+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[5][(3+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[5][(4+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[6][(4+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[6][(4+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[5][(6+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[6][(6+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
leds[LEDLINE[5][(7+counter)%8]] = CRGB (ledc[plate][0],ledc[plate][1],ledc[plate][2]);
FastLED.show();
delay(150);
counter++;
if(counter>=8){
counter-=8;
}
plate++;
if(plate>=45){
plate-=45;
}
}
void visualize_music(int VOLUME){
if(VOLUME<=80){
LOWMODE();
}
else if(VOLUME>80&&VOLUME<=230){
MIDMODE();
}
else if(VOLUME>230){
HIGHMODE();
}
}
|
-
-
|