I have a short program that controls an RGB LED strip. Because the library is so small, I want to put it into a single file so it can simply be copied/pasted into a project.
Everything's working fine except for a single include which doesn't work when copied directly into the code.
I've tried to directly copy and paste in the code from #include "cRGB.h", which happens to be a simple struct. definition (struct cRGB { uint8_t g; uint8_t r; uint8_t b; };).
See the full code below.
It is my understanding that #include simply 'copies' code from a file directly into the document. If that is the case, why does this code fail to compile?
#include "cRGB.h"
class WS2812 {
public:
WS2812(uint16_t num_led);
~WS2812();
void setOutput(uint8_t pin);
cRGB get_crgb_at(uint16_t index);
uint8_t set_crgb_at(uint16_t index, cRGB px_value);
uint8_t set_subpixel_at(uint16_t index, uint8_t offset, uint8_t px_value);
void sync();
private:
uint16_t count_led;
uint8_t *pixels;
void ws2812_sendarray_mask(uint8_t *array,uint16_t length, uint8_t pinmask,uint8_t *port, uint8_t *portreg);
const volatile uint8_t *ws2812_port;
volatile uint8_t *ws2812_port_reg;
uint8_t pinMask;
};
WS2812 LED(4); // 1 LED
cRGB value1;
cRGB value2;
cRGB value3;
cRGB value4;
void setup() {
LED.setOutput(3); // Digital Pin 9
}
void loop() {
value1.b = 0; value1.g = 255; value1.r = 255; // RGB Value
LED.set_crgb_at(0, value1); // Set value at LED found at index 0
LED.sync(); // Sends the value to the LED
delay(500); // Wait 500 ms
}
Here are the errors:
/var/folders/fr/vj8c52911yg97mycb0d8xjk00000gn/T//ccoFxRCe.ltrans0.ltrans.o: In function setup': /Users/*/Documents/Arduino/fastLEDcompressed/fastLEDcompressed.ino:39: undefined reference to WS2812::setOutput(unsigned char)'
/var/folders/fr/vj8c52911yg97mycb0d8xjk00000gn/T//ccoFxRCe.ltrans0.ltrans.o: In function loop': /Users/*/Documents/Arduino/fastLEDcompressed/fastLEDcompressed.ino:44: undefined reference to WS2812::set_crgb_at(unsigned int, cRGB)'
/Users//Documents/Arduino/fastLEDcompressed/fastLEDcompressed.ino:45: undefined reference to WS2812::sync()' /var/folders/fr/vj8c52911yg97mycb0d8xjk00000gn/T//ccoFxRCe.ltrans0.ltrans.o: In function _GLOBAL__sub_I_LED':
/Users//Documents/Arduino/fastLEDcompressed/fastLEDcompressed.ino:31: undefined reference to WS2812::WS2812(unsigned int)' /var/folders/fr/vj8c52911yg97mycb0d8xjk00000gn/T//ccoFxRCe.ltrans0.ltrans.o: In function _GLOBAL__sub_D_LED':
/Users/*/Documents/Arduino/fastLEDcompressed/fastLEDcompressed.ino:31: undefined reference to `WS2812::~WS2812()'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Uno.