I am trying to create a program to operate my arduino based LED controller. I'm pretty sure that my C# program is outputting to serial port correctly as I double checked the output in Debug.WriteLine(). The program is supposed to send information to the arduino in the following format (newlines included):
mode
number of colors
blend speed
beats until color change
Red <---
Green <---
Blue <---
Brightness <---
the last 4 are the only ones that matter for now as I am trying to get the LED's to show up one solid color first before worrying about other modes or patterns. The debug writeline loop output of my last test looks like this
1
1
0
1
209
255
255
219
This should be translating to the relevant arduino variables the same way but instead, I only get white light that seems to randomly brighten or darken when I mess with the color/brightness sliders
My code for the arduino is below. I am very new to this so it's probably not even close to right. getData() at the bottom is the function that most likely is the culprit, but I'll put the rest in just in case:
#include <SPI.h>
#include <Adafruit_DotStar.h>
#define NUMPIXELS 60
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DOTSTAR_BRG);
// Variables
int mode;
int numColors;
int fadeSpeed;
int BBCC;
int R;
int G;
int B;
int Bright;
String buff;
void setup() {
strip.begin();
strip.show();
//Serial.begin(9600);
}
void loop() {
getData();
if (mode == 1)
{
//strip.setPixelColor(0, R, G, B);
strip.setBrightness(Bright);
strip.show();
}
}
void getData()
{
// if (Serial.available() > 0)
// {
buff = Serial.read();
int result = buff.toInt();
mode = result;
if (mode != -1)
{
buff = Serial.read();
int result = buff.toInt();
numColors = result;
buff = Serial.read();
result = buff.toInt();
fadeSpeed = result;
buff = Serial.read();
result = buff.toInt();
BBCC = result;
buff = Serial.read();
result = buff.toInt();
R = result;
buff = Serial.read();
result = buff.toInt();
G = result;
buff = Serial.read();
result = buff.toInt();
B = result;
buff = Serial.read();
result = buff.toInt();
Bright = result;//Serial.read();
strip.setPixelColor(0, R, 0, 0);
//strip.setBrightness(Bright);
strip.show();
}
else
{
strip.setPixelColor(0, R, 0, 0);
//strip.setBrightness(Bright);
strip.show();
}
// }
}