创建头文件并使用FastLED库中的CRGB LED阵列时出错
Error to create header file and use CRGB LED array from FastLED library
我正在使用可寻址LED的Arduino项目,我正在使用FastLED.h库。
为了简化我的程序,我想创建一个名为LedsHorloge.h的库,从中我将调用函数Jauge(int tour, int numberLeds, int brightness, CRGB* ledTable)
来点亮我的LED灯带。
我是C++的新手。
在Arduino IDE中,这是我得到的错误:
D:ProgrammationArduinolibrarieslibrariesJaugeLED/LedsHorloge.h:16:8: note: void LedsJauge::Jauge(int, int, int, CRGB*)
void Jauge(int tour, int numberLeds, int brightness, CRGB* ledTable);
^
D:ProgrammationArduinolibrarieslibrariesJaugeLED/LedsHorloge.h:16:8: note: no known conversion for argument 4 from 'CRGB (*)[32]' to 'CRGB*'
exit status 1
no matching function for call to 'LedsJauge::Jauge(int&, int, int, CRGB (*)[32])'
当我在Arduino IDE:中运行此代码时,会发生此错误
#include <LedsHorloge.h>
#include "FastLED.h"
#define LED_PIN 6
#define NUMBER_LEDS 32
#define BRIGHTNESS 100
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define VITESSE_JAUGE 150 // Delay milliseconds
CRGB leds[NUMBER_LEDS];
#define UPDATES_PER_SECOND 100
int tour = 0 ; // Compte le nombre de tour dans le loop
int pinButton = 8; // Pin qui déclenche la fonction "Jauge"
boolean flag = false ;
LedsJauge jauge(LED_PIN); // This is the object I create
void setup() {
delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUMBER_LEDS).setCorrection( TypicalLEDStrip ); // Initialisation de la bande de leds
Serial.begin(9600);
FastLED.clear(); // Fonction d'initialisation, encore mal connue
pinMode(pinButton, INPUT_PULLUP) ;
InitBandeLeds(); // Eteint toutes les leds si elles sont allumées
FastLED.show(); // Applique la valeur HSV définie dans la variable "leds"
}
void loop() {
// tant que le bouton n'est pas activé, le drapeau reste false
if ( digitalRead(pinButton) == LOW ){
flag = true ;
}
// lorsque le drapeau devient true on rentre dans la condition
if (flag){
if ( tour < NUMBER_LEDS ){ tour += 1; } // A chaque loop la variable est incrémenté de 1
jauge.Jauge(tour, NUMBER_LEDS, BRIGHTNESS, &leds); // ERROR COMES FROM THIS LINE
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
delay(VITESSE_JAUGE); // régle la vitesse d'allumage des leds
}
}
// Fonction qui éteint le bandeau de leds
void InitBandeLeds(){
for( int i = 0; i < NUMBER_LEDS; i++) {
if ( tour - i >0 ){
leds[i] = CHSV( 0, 0, 0) ;
}
}
}
这是我的标题LedsHorloge.h
#ifndef LedsHorloge_h
#define LedsHorloge_h
#include <Arduino.h>
#include "FastLED.h"
class LedsJauge
{
public:
LedsJauge(int pin);
// A chaque tour une led supplémentaire de la jauge est allumée
void Jauge(int tour, int numberLeds, int brightness, CRGB* ledTable);
private:
int _pin;
};
#endif
这是我的源代码LedsHorloge.cpp
#include <Arduino.h>
#include "FastLED.h"
#include "LedsHorloge.h"
LedsJauge::LedsJauge(int pin)
{
_pin = pin;
}
void LedsJauge::Jauge(int tour, int numberLeds, int brightness, CRGB* ledTable)
{
for( int i = 0; i < numberLeds; i++) {
if ( tour - i >0 ){
ledTable[i] = CHSV( 100, 187, brightness) ;
}
}
return;
}
我不知道如何在对象CRGB leds[NUMBER_LEDS];
上创建指针。
我从另一个论坛得到了答案,解决方案是替换:
jauge.Jauge(tour, NUMBER_LEDS, BRIGHTNESS, &leds);
通过
jauge.Jauge(tour, NUMBER_LEDS, BRIGHTNESS, leds);
然而,我真的不明白为什么我不能使用变量的内存值,而我在函数Jauge的声明中使用指针,让我们看看:
void LedsJauge::Jauge(int tour, int numberLeds, int brightness, CRGB* ledTable)
这是因为
CRGB leds[NUMBER_LEDS];
leds已经是一个指针;只是它是一个常量指针。即不能改变变量的地址。
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 为什么我的变量没有更新,我的 LED 没有亮起?
- 如何避免LED在循环状态变化中闪烁?
- ATMEGA32 8x8 LED 矩阵控制
- 如何修复 Arduino LED 串控制器的代码?
- 如何让 LED 代码从键盘按下运行
- 创建头文件并使用FastLED库中的CRGB LED阵列时出错
- 使用LPC1768控制 LED
- 我在微控制器STM32F373发现中点亮LED的问题
- 使用 ARDUINO 和处理在 8x8 LED 矩阵上显示数据时出现问题
- Adafruit NeoPixel库在寻址超过7个LED灯条时不起作用
- 尝试使用异或和位移运算符切换随机 LED
- 使用串行监视器 arduino 控制 LED
- 如何修复闪烁的led矩阵和液晶菜单屏幕
- Arduino RGB LED随机PWM级别
- wx小部件和代码:块 - 缺少 <wx/led.h> 用于 LED 组件
- 对于循环:LED 在 Arduino 上无法正确显示
- C++/Arduino 闪烁 LED 不同的间隔
- 如何逆转Arduino中的LED矩阵
- 根据通过/失败返回,在MFC对话框中更改LED颜色