pd -> arduino (teensy) -> neopixel (led)
see example codes for arduino and pure data below:
neopixel controlled via pure data
pure data sends via the comport object serial data to the arduino. the arduino reads the serial data and starts a sequence (if-loop) corresponding to the serial data.
example files (arduino + pd) below:
////////////////////////////////////////////ARDUINO CODE START ///////////
//modded neopixel example from adafruit by uli/praxistest
//
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6
// How many NeoPixels are attached to the Arduino?
int randomVals[10]; // HOW MANY LIGHTS!
int randomValueNumber = 10; // HOW MANY LIGHTS
#define NUMPIXELS 10 // HOW MANY LIGHTS
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, data rate to 9600 bps
pixels.begin();
pinMode(13, OUTPUT);
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print(„I received: „);
Serial.println(incomingByte);
}
if (incomingByte == 49) { //this part should be a looping till next incoming! now it only repeats 1x
pixels.setPixelColor(8, pixels.Color(255, 255, 255)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(30);
pixels.setPixelColor(8,pixels.Color(100,100,100));
pixels.show();
delay(30);
}
if (incomingByte == 50) { //this part should be a looping till next incoming!
pixels.setPixelColor(8, pixels.Color(0, 0, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
}
}
////////////////////////////////////////////ARDUINO CODE END////////////////////////
and the pd file as text:
#N canvas 409 36 1031 627 10;
#X obj 488 438 comport 1 9600;
#X msg 314 61 bits 8;
#X msg 340 87 stopbit 0;
#X msg 400 147 parity 0;
#X text 467 146 parity 1=even \, -1=odd \, 0=off;
#X text 363 60 databits 5 \, 6 \, 7 \, 8;
#X obj 488 412 r comctl;
#X obj 674 438 s comctl;
#X text 500 166 use handshake xon/off 1=on 0=off;
#X text 512 186 cts/rts hardwarehandshake 1=on 0=off;
#X msg 460 207 pollintervall 1;
#X text 761 206 (default is 1 tick 1ms);
#X msg 482 229 close;
#X text 521 228 Close Serial port;
#X msg 666 413 devicename /dev/ttyS1;
#X text 742 432 Danger !!! you can open every file in your system and
maybe if suid is root damage the system.;
#X text 35 511 (C) 1998-2005 IEM Winfried Ritsch GPL (see LICENSE.txt)
;
#X text 550 249 Open serial port by number;
#X text 878 413 open the serial port by name;
#X msg 367 300 help;
#X text 560 206 set poll interval for read in ms;
#X msg 321 254 info;
#X floatatom 569 497 10 0 0 1 baud – -;
#X floatatom 644 538 3 0 0 3 parity – -;
#X floatatom 669 538 3 0 0 2 stop – -;
#X floatatom 694 537 3 0 0 3 data – -;
#X floatatom 770 499 3 0 0 0 port – -;
#X msg 544 291 devices;
#X text 602 290 print available devices (wait for it…);
#X obj 142 113 key;
#X obj 170 130 sel 0;
#X floatatom 249 147 4 0 0 0 ascii – -;
#X msg 524 271 open 0;
#X obj 719 503 tgl 15 0 empty empty rts/cts -10 20 1 11 -24198 -258699
-1 0 1;
#X obj 745 519 tgl 15 0 empty empty xon/xoff -14 20 1 11 -24198 -258699
-1 0 1;
#X text 508 537 serial packet format:;
#X text 660 487 handshaking:;
#X text 466 569 flow control inputs:;
#X obj 594 569 tgl 15 0 empty empty dsr 0 20 1 11 -24198 -258699 -1
0 1;
#X obj 619 569 tgl 15 0 empty empty cts 0 20 1 11 -24198 -258699 -1
0 1;
#N canvas 307 43 789 479 bauds 0;
#X msg 319 274 baud 57600;
#X msg 357 312 baud 230400;
#X msg 338 293 baud 115200;
#X msg 300 255 baud 38400;
#X msg 281 236 baud 19200;
#X msg 262 217 baud 9600;
#X msg 243 198 baud 4800;
#X msg 224 179 baud 2400;
#X obj 431 403 s comctl;
#X msg 205 160 baud 1800;
#X msg 186 141 baud 1200;
#X msg 167 122 baud 600;
#X msg 148 103 baud 300;
#X msg 129 84 baud 200;
#X msg 91 46 baud 134;
#X msg 72 27 baud 110;
#X msg 53 8 baud 75;
#X msg 34 -11 baud 50;
#X msg 15 -30 baud 0;
#X msg 110 65 baud 150;
#X text 368 255 this is a special baud rate that can be configured
;
#X text 12 -48 standard baud rates for linux:;
#X text 64 -31 0 deasserts control lines and resets the serial port
;
#X text 435 312 won’t work with standard setup. See setserial;
#X msg 431 231 baud \$1;
#X text 518 269 on-the-fly with setserial:;
#X text 519 298 gives 14400 baud instead of 38400;
#X text 517 284 „setserial /dev/ttyS0 spd_cust divisor 8“;
#X msg 419 163 115200;
#X floatatom 392 104 7 1 115200 1 divisor – -;
#X obj 431 192 / 1;
#X obj 392 123 sel 0;
#X floatatom 431 212 7 0 0 0 – – -;
#X text 482 103 (1-115200);
#X obj 419 143 t b f;
#X text 390 86 On Windows some other baud rates might work:;
#X connect 0 0 8 0;
#X connect 1 0 8 0;
#X connect 2 0 8 0;
#X connect 3 0 8 0;
#X connect 4 0 8 0;
#X connect 5 0 8 0;
#X connect 6 0 8 0;
#X connect 7 0 8 0;
#X connect 9 0 8 0;
#X connect 10 0 8 0;
#X connect 11 0 8 0;
#X connect 12 0 8 0;
#X connect 13 0 8 0;
#X connect 14 0 8 0;
#X connect 15 0 8 0;
#X connect 16 0 8 0;
#X connect 17 0 8 0;
#X connect 18 0 8 0;
#X connect 19 0 8 0;
#X connect 24 0 8 0;
#X connect 28 0 30 0;
#X connect 29 0 31 0;
#X connect 30 0 32 0;
#X connect 31 1 34 0;
#X connect 32 0 24 0;
#X connect 34 0 28 0;
#X connect 34 1 30 1;
#X restore 314 37 pd bauds;
#X msg 420 167 xonxoff \$1;
#X obj 387 167 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
-1 0 1;
#X msg 440 187 rtscts \$1;
#X obj 408 187 tgl 15 0 empty empty empty 0 -6 0 8 -241291 -250685
-1 0 1;
#X text 17 -4 comport: a serial port interface;
#X msg 248 172 13;
#X obj 795 500 tgl 15 0 empty empty open -6 20 1 11 -24198 -258699
-1 0 1;
#X msg 565 312 ports;
#X obj 820 534 print port_list;
#X text 611 311 list available ports on right outlet;
#X msg 646 393 hupcl \$1;
#X obj 614 394 tgl 15 0 empty empty empty 17 7 0 10 -257985 -258113
-1 0 1;
#X text 704 386 hang up connection on last close;
#X text 717 398 (not on Windows);
#X obj 934 490 print other;
#X text 205 176 <CR>:;
#X text 143 254 status list on right outlet:;
#X text 257 300 print usage info:;
#X obj 845 497 tgl 15 0 empty empty hupcl -6 20 1 11 -24198 -258699
-1 0 1;
#X msg 452 110 1;
#X msg 482 110 1.5;
#X msg 513 110 2;
#X text 444 127 number of stopbits (Windows only);
#X msg 380 127 stopbit \$1;
#X text 403 86 extra stopbit 1=on \, 0=off (linux \, MacOS);
#X text 12 112 or from the terminal:;
#X floatatom 870 510 10 0 0 1 rxerrors – -;
#X obj 569 460 route baud dsr cts parity stop data rtscts xonxoff port
open ports hupcl rxerrors;
#X msg 503 250 open 3;
#X msg 57 391 49;
#X msg 151 388 50;
#X text 37 526 2006-2010 Martin Peach slightly modded by uli/praxistest
for neopixel tests;
#X text 53 359 press this 2 message boxes to trigger 2 different if-loops
on the arduino;
#X connect 0 1 68 0;
#X connect 1 0 7 0;
#X connect 2 0 7 0;
#X connect 3 0 7 0;
#X connect 6 0 0 0;
#X connect 10 0 7 0;
#X connect 12 0 7 0;
#X connect 14 0 7 0;
#X connect 19 0 0 0;
#X connect 21 0 0 0;
#X connect 27 0 7 0;
#X connect 29 0 30 0;
#X connect 30 1 31 0;
#X connect 30 1 0 0;
#X connect 32 0 7 0;
#X connect 41 0 7 0;
#X connect 42 0 41 0;
#X connect 43 0 7 0;
#X connect 44 0 43 0;
#X connect 46 0 0 0;
#X connect 48 0 7 0;
#X connect 51 0 7 0;
#X connect 52 0 51 0;
#X connect 60 0 64 0;
#X connect 61 0 64 0;
#X connect 62 0 64 0;
#X connect 64 0 7 0;
#X connect 68 0 22 0;
#X connect 68 1 38 0;
#X connect 68 2 39 0;
#X connect 68 3 23 0;
#X connect 68 4 24 0;
#X connect 68 5 25 0;
#X connect 68 6 33 0;
#X connect 68 7 34 0;
#X connect 68 8 26 0;
#X connect 68 9 47 0;
#X connect 68 10 49 0;
#X connect 68 11 59 0;
#X connect 68 12 67 0;
#X connect 68 13 55 0;
#X connect 69 0 7 0;
#X connect 70 0 0 0;
#X connect 71 0 0 0;