-
Notifications
You must be signed in to change notification settings - Fork 13
pure data
Christopher Konopka edited this page May 7, 2019
·
1 revision
arduivisPD is a template paradigm that streamlines the interconnectivity potential of an Arduino with Pure Data.
-
Press "device" to find the correct device number and type the number into the number box above "open" to make the connection; wait 2 seconds
-
Start polling.
-
You're done!
At this point the data should be flowing between PD and the Arduino, providing a real-time link for rapid-prototyping.
- waiting 2 seconds sounds absurd, but it helps ensure that the connection is made. When there is a large number of inputs sometimes the serial protocol takes a little longer to establish itself
void setup()
{
// Create/open serial port
Serial.begin(9600);
}
void loop()
{
// Slider from Pure Data
int pdSlider;
// Parse incoming Pure Data slider values
// from Pure Data, to Arduino
pdSlider = Serial.parseInt();
}
void setup()
{
// Create/open serial port
Serial.begin(9600);
}
void loop()
{
// Sliders from pd
int pdSlider1, pdSlider2, pdSlider3, pdSlider4;
// Parse incoming pd slider values
// from pd, to Arduino
pdSlider1 = Serial.parseInt();
pdSlider2 = Serial.parseInt();
pdSlider3 = Serial.parseInt();
pdSlider4 = Serial.parseInt();
}
void setup()
{
// Create/open serial port
Serial.begin(9600);
// Define LED mode
// PWM LED
pinMode(3, OUTPUT);
}
void loop()
{
// Loop variables
int lp = 0;
// Loop #1
// Incremental Loop
for(lp = 0; lp<=255; lp++) // Create incremental loop
{
// Incremental loop values to LED
// Controls PWM fade
analogWrite(3,lp);
// Incremental loop values to serial buffer
// [comport] object
// to Pure Data, from Arduin o
Serial.println(lp);
}
// Loop #2
// Decremental Loop
for(lp = 255; lp>=0; lp--) // Create decremental loop
{
// Deremental loop values to LED
// Controls PWM fade
analogWrite(3,lp);
// Decremental loop values to serial buffer
// [comport] object
// to Pure Data, from Arduino
Serial.println(lp);
}
void setup()
{
// Create/open serial port
Serial.begin(9600);
// Define LED mode
// PWM LED
pinMode(3, OUTPUT);
}
void loop()
{
// Loop variables
int lp = 0;
int startIncrement = 0;
int incrementLoopRange = 255;
int startDecrement = 255;
int decrementLoopRange = 0;
// Loop Function
lp = loopSystem(startIncrement, incrementLoopRange, startDecrement, decrementLoopRange);
}
int loopSystem(int startIncrement, int incrementLoopRange, int startDecrement, int decrementLoopRange)
{
int lp;
// Loop #1
// Incremental Loop
for(lp = startIncrement; lp < incrementLoopRange; lp++)
{
// Incremental loop values to LED
// Controls fade of 4 LEDs
analogWrite(3, lp);
analogWrite(5, lp - 13);
analogWrite(6, lp + 47);
analogWrite(9, lp - 60);
// Incremental loop values to serial buffer
// [comport] object
// to Pure Data, from Arduino
Serial.print(lp);
Serial.print(" ");
Serial.print(lp - 13);
Serial.print(" ");
Serial.print(lp + 47);
Serial.print(" ");
Serial.println(lp - 60);
delay(10);
}
// Loop #2
// Decremental Loop
for(lp = startDecrement; lp > decrementLoopRange; lp--)
{
// Deremental loop values to LED
// Controls fade of 4 LEDs
analogWrite(3, lp);
analogWrite(5, lp - 13);
analogWrite(6, lp + 47);
analogWrite(9, lp - 60);
// Decremental loop values to serial buffer
// [comport] object
// to Pure Data, from Arduino
Serial.print(lp);
Serial.print(" ");
Serial.print(lp - 13);
Serial.print(" ");
Serial.print(lp + 47);
Serial.print(" ");
Serial.println(lp - 60);
delay(10);
}
}
This example demonstrates a flow of data from sliders in PD, routed to an Arduino where the data is parsed in the serial buffer and then sent from the Arduino back to PD. The patch below demonstrates this paradigm and the code is below the image.
void setup()
{
// Create/open serial port
Serial.begin(9600);
// Define LED mode
// PWM LED
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(9, OUTPUT);
}
void loop()
{
// Sliders from pd
word pdSlider1, pdSlider2, pdSlider3, pdSlider4;
// Parse incoming pd slider values
// from pd, to Arduino
pdSlider1 = Serial.parseInt();
pdSlider2 = Serial.parseInt();
pdSlider3 = Serial.parseInt();
pdSlider4 = Serial.parseInt();
// Write parsed values to LEDs
// Fading LED
// from pd, to Arduino
analogWrite(3, pdSlider1);
analogWrite(5, pdSlider2);
analogWrite(6, pdSlider3);
analogWrite(9, pdSlider4);
// Print output of slider to serial buffer
// This is mainly for debugging
Serial.print(pdSlider1);
Serial.print(" ");
Serial.print(pdSlider2);
Serial.print(" ");
Serial.print(pdSlider3);
Serial.print(" ");
Serial.println(pdSlider4);
}