I'm trying to change the LED colour by sending commands over USB to the Digispark.
The commands are received and echoed back, but the LED does not change colour.
I can change the LED colour if I remove the USB-code.
Is there any other way I can control the DigiLED from the computer?
#include <Adafruit_NeoPixel.h>
#include <DigiUSB.h>
#define USB_CFG_DEVICE_NAME 'D','i','g','i','B','l','i','n','k'
#define USB_CFG_DEVICE_NAME_LEN 9
#define PIN 1
#define NUMPIXELS 1
int delayval = 500; // delay for half a second
byte in = 0;
int Blue = 0;
int Red = 0;
int Green = 0;
int next = 0;
bool dataread = false;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
void setup()
{
DigiUSB.begin();
pixels.begin(); // This initializes the NeoPixel library.
setLED(Red, Green, Blue);
}
void loop()
{
DigiUSB.refresh();
if (DigiUSB.available() > 0)
{
in = 0;
in = DigiUSB.read();
if (next == 0)
{
if (in == 115) {
next = 1;
DigiUSB.print("Start; ");
}
}
else if (next == 1) {
Red = in;
DigiUSB.print("Red:");
DigiUSB.print(Red, DEC);
next = 2;
}
else if (next == 2) {
Green = in;
DigiUSB.print(" Green:");
DigiUSB.print(Green, DEC);
next = 3;
}
else if (next == 3) {
Blue = in;
DigiUSB.print(" Blue:");
DigiUSB.print(Blue, DEC);
next = 0;
dataread = true;
}
if (dataread)
{
pixels.setPixelColor(0, pixels.Color(Red, Green, Blue));
pixels.show(); // This sends the updated pixel color to the hardware.
dataread = false;
DigiUSB.println(" END");
}
}
}