Heres where I'm at. I've read through Beginning Arduino and the Arduino Cookbook, and have read pretty much every post (it seems) on Arduino and serial comm. My angle of attack on this project is to send char strings and pars them, in order to send multiple variables to the lightuino at once (obviously its still serial). Heres my patch that works great on the uno (using Serial.xxxx class), but not on the lightuino. When i switch the Serial.xxxx class to Usb.xxxx class for the lightuino it will only print the first character of the string then stops working at that point. Is there something different about the Usb.xxxx and using SPI that I need to account for? I'm not going to be controlling one rgb led like in this example, but the concept of parsing strings is what I'm after because I can translate that into my project. Thanks so much for your help! Heres the code- Cheers! Justin
#include <lightuino5.h>
LightuinoSink sinks;
LightuinoSourceDriver sources;
FlickerBrightness pwm(sinks);
// Project 10 - Serial controlled mood lamp///// This is the project out of Beginning Arduino that Im studying
char buffer[18];
char val[0];
int red, green, blue; /////// these parts of the code aren't involved with what I'm doing
int RedPin = 11;
int GreenPin = 10;
int BluePin = 9;
void setup()
{
{pwm.StartAutoLoop(4096);}
Serial.begin(9600); ///or Usb.begin(); for the lightuino
}
void loop()
{
if (Serial.available() > 0) { ///on lightuino Usb.available() etc. throughout the code
int index=0;
delay(100); // let the buffer fill up
int numChar = Serial.available();
if (numChar>15) {
numChar=15;
}
while (numChar--) {
buffer[index++] = Serial.read();
}
splitString(buffer);
}
}
void splitString(char* data) {
Serial.print("Data entered: ");
Serial.println(data);
char* parameter;
parameter = strtok (data, " ,");
while (parameter != NULL) {
setLED(parameter);
delay(30);
parameter = strtok (NULL, " ,");
}
// Clear the text and serial buffers
for (int x=0; x<16; x++) {
buffer[x]='\0';
}
Serial.flush();
}
void setLED(char* data) {
if ((data[0] == 'r') || (data[0] == 'R')) {
int Ans = strtol(data+1, NULL, 10);
Ans = constrain(Ans,0,255);
analogWrite(GreenPin, Ans); ////on the lightuino I'd use something like pwm.brightness[variable 1 from string] = (variable 2 from string)
Serial.print("Red is set to: ");
Serial.println(Ans);
}
if ((data[0] == 'g') || (data[0] == 'G')) {
int Ans = strtol(data+1, NULL, 10);
Ans = constrain(Ans,0,255);
analogWrite(GreenPin, Ans);
Serial.print("Green is set to: ");
Serial.println(Ans);
}
if ((data[0] == 'b') || (data[0] == 'B')) {
int Ans = strtol(data+1, NULL, 10);
Ans = constrain(Ans,0,255);
analogWrite(BluePin, Ans);
Serial.print("Blue is set to: ");
Serial.println(Ans);