Hello, I'm having some problems sending data from Pure Data to Arduino. I am using PD to control 16 LEDs with only 2 on at any one time.
I have a discussion going on on the PD forum here, but thought some help the Arduino end may be useful.
In PD I am reading a text file and then sending values to control two LEDs (LED1 and LED2) and their PWM. The LED2PWM = 255-LED1PWM.
I have found this to half-work (see joe_working.zip) sending 2 values (LED1 and PWM1).
With this code I get a good PWM increase/decrease on the correct LED
I need to send a string of 3 values out of PD and read them into Arduino, however - when I add another message to the PD end everything stops working (see original_code_3).
I also tried another approach which choked up and turned random LEDs on (see using_serialprint2_example).
Finally I attempted to trick the joe_working patch and sketch into doing what I wanted by alternating the values between different LEDs (see joe_working.zip).
All text files and abstractions are included in each zip file.
Any help would be really greatly appreciated. I am very stuck, confused and frustrated lol.
The Arduino code is attached in the zip files. There are three different codes to go with each PD patch. I thought it would make it easier to match them up. Here is some Arduino code for one of the patches:
#include <Tlc5940.h>
int ledNo1 =0;
int ledNo2 =0;
int pwmVal =0;
void setup() {
Serial.begin(57600);
Tlc.init();
}
void loop() {
while(Serial.available()){
int intVal1=Serial.parseInt();
int pwmVal=Serial.parseInt();
int intVal2=Serial.parseInt();
if (intVal1 <= 16){
ledNo1=intVal1-1;
}
if (intVal2 <= 16){
ledNo2=intVal2-1;
}
Tlc.set(ledNo1, pwmVal);
Tlc.set(ledNo2, pwmVal);
Tlc.update();
delay(50);
}
Tlc.clear();
}
I have done Serial comms. successfully before between different Arduinos and other software etc.
The problems with PD is that it does not allow you to send characters which makes delimiting difficult. If you look at the attached file joe_working you will see that this works, however when 1 additional value is added it does not. I will have a look at your examples and see if they help.