Blinker使用求助-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2662|回复: 4

[已解答] Blinker使用求助

[复制链接]
发表于 2019-8-19 23:01 | 显示全部楼层 |阅读模式
求助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();
  }
}


IMG_3819.PNG
IMG_3818.PNG
 楼主| 发表于 2019-8-19 23:02 | 显示全部楼层
更正一下,蓝牙模块是JDY-18
发表于 2019-8-19 23:18 | 显示全部楼层
串口调试,看是否正常收到数据:1.如果正常接收数据,但不是你预计的效果,说明你程序有问题;
2.如果没有收到,那测试例程,看是否正常,如果正常,则说明是你程序问题。
3.如果使用例程,仍然无法正常收发数据,那检查硬件连接
 楼主| 发表于 2019-8-20 11:12 | 显示全部楼层
coloz 发表于 2019-8-19 23:18
串口调试,看是否正常收到数据:1.如果正常接收数据,但不是你预计的效果,说明你程序有问题;
2.如果没有 ...

使用例程的时候,串口监视器还是没有反应,请问硬件的连接有什么问题吗?
我使用了拓展板,蓝牙模块用的3.3V输入,TXD连2,RXD连3,没有反应,手机能连接上,但是好像收发不了数据是什么原因呢?
发表于 2019-8-20 16:27 | 显示全部楼层
EdwinYu 发表于 2019-8-20 11:12
使用例程的时候,串口监视器还是没有反应,请问硬件的连接有什么问题吗?
我使用了拓展板,蓝牙模块用的3 ...

确定连线是否正确,包括VCC、GND是否正确,确定是3.3V供电还是5V供电,确定程序中引脚和波特率是否正确,打开串口监视器,看是否正常收发数据。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 20:34 , Processed in 0.090826 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表