Need guidance on how to make this class accept an object as an argument.
i have awesome led strips running shows, code rigid , unflexible trying convert oop style. using fastled library.
here small piece of working code wrote. make movingrainbow class accept crgb object argument, movingrainbow::start() ...
here small piece of working code wrote. make movingrainbow class accept crgb object argument, movingrainbow::start() ...
code: [select]
#include "arduino.h"
#include "fastled.h"
#include "mydefines.h"
#define data_pin_top 10
#define data_pin_bottom 16
#define num_leds 28
#define delta_index 10
#define start_index 0
crgb topleds[num_leds];
crgb bottomleds[num_leds];
//////////////////////////////moving rainbow class////////////////////////////////////////
class movingrainbow
{
int rainbowspeed;
bool updateflag = 0;
public:
movingrainbow(int rspeed){
rainbowspeed = rspeed;
}
void start(){
fill_rainbow(topleds, num_leds, start_index, delta_index);
fastled.show();
updateflag = 1;
}
void off(){
updateflag = 0;
}
};
////////////////////////////// end of moving rainbow class /////////////////////////////////
movingrainbow mrainbow(400);
void setup() {
delay(2000);
fastled.addleds<ws2812b, data_pin_top, grb>(topleds, num_leds);
fastled.addleds<ws2812b, data_pin_bottom, grb>(bottomleds, num_leds);
mrainbow.start();
}
void loop() {
}
here small piece of working code wrote. make movingrainbow class accept crgb object argument, movingrainbow::start() ...are saying want start() member function accept parameter: namely crgb object?
i'd start overloading start() function take 1 of objects:
code: [select]
void start(const crgb colors){
fill_rainbow(colors, num_leds, start_index, delta_index);
fastled.show();
updateflag = 1;
}
and call function:
code: [select]
mrainbow.start(topleds);
see if compiles...
Arduino Forum > Using Arduino > Programming Questions > Need guidance on how to make this class accept an object as an argument.
arduino
Comments
Post a Comment