I am currently sending an array from Supercollider to Arduino.
My problem is on the Arduino code side, I am struggling as I am not familiar with the language.
Basically, I want to read the data, from SuperCollider, in Arduino as an Array, and then isolate each number from that Array.
Can some one please help me or point me in the right direction
I am sending an array of ascii integers all at the same time from supercollider to the arduino via the serial port.
So basically where I am stuck, is how arduino picks the array up as an array and can assign each integer to a different variable. (currently it seems to pick each integer from the array separately)
//arduino code a friend gave me to look at, from the void loop onwards
void loop()
{
int rxdata, channel, val1, val2, val3;
int val = 0;
int dumpme = 0;
if (Serial.available() > 0){ //wait for data
val = Serial.read();
if (val == 35) //indicates # start of packet and channel number
{while (Serial.available() < 1){}; //dont do anything until that next byte gets in
channel = Serial.read(); //first byte is the channel
if(channel > 57) //of course its ascii encoded hex so we need to turn it into an int
{
channel -= 55;
}
else channel -= 48;
while (Serial.available() < 1){};
val1 = Serial.read();
if(val1 > 57)
{
val1 -= 55;
}
else val1 -= 48;
rxdata = val1 << 8; // first byte specifies top 4 bits of brightness so shift it up, now val = 111100000000
while (Serial.available() < 1){}; //dont do anything until that next byte gets in
val2 = Serial.read(); //this byte has the middle four bits of brightness 000011110000
if(val2 > 57) //is it the ascii for A to F i.e. 65 to 70
{
val2 -= 55; //A in hex is 10 in dec.
}
else val2 -= 48;
val2 = val2 << 4; //this byte has the middle four bits of brightness 000011110000
rxdata += val2;
while (Serial.available() < 1){}; //dont do anything until that next byte gets in
val3 = Serial.read(); //this byte has the bottom four bits of brightness 00001111
if(val3 > 57) //is it the ascii for A to F
{
val3 -= 55; //convert it to a number
}
else val3 -= 48; //otherwise its the ascii for 0 to 9 i.e. 48 to 57
rxdata += val3; //now rxdata has the three bytes of info in it 1111 1111 1111
Tlc.set(channel, rxdata);
updateflag = 1;
}
else
{dumpme = Serial.read();}
};
//the actual lighting part
if ((millis()%5 == 0) && (updateflag == 1)) //every 5ms as long as the updateflag says so
{
Tlc.update();
updateflag = 0;
}
}
Slightly OT hint: Your sketch is easier to read and understand if you use literal constants, instead of decimal numbers, thusly:
if (val == '#') //indicates # start of packet and channel number
{while (Serial.available() < 1){}; //dont do anything until that next byte gets in
channel = Serial.read(); //first byte is the channel
if(channel > '9') //of course its ascii encoded binary so we need to turn it into an int
{
channel -= '7';
}
else channel -= '0';