User tutorial No1: Parat+ and OpenFrameWorks app Final polishing …

Parat+ with EPS8266 by Adafruit with LSM9S0 controlling a 64 LED NeoPixel matrix.

Parat+WithArduinoESP6288

The ESP6288 breakout board from Adafruit sending the data of the 9DOF sensor LSM9S0 (9 degrees of freedom) to Parat+.

All required scaling is done in Parat+.

 

Arduino Code:

#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <OSCBundle.h>
#include <OSCBoards.h>
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>

#define NEO_PIN            6
#define NUMPIXELS      64
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NEO_PIN, NEO_GRB + NEO_KHZ800);

//UDP communication
EthernetUDP Udp;
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // you can find this written on the board of some Arduino Ethernets or shields

//the Arduino’s IP
IPAddress ip(192, 168, 5, 177);

//port numbers
const unsigned int inPort = 8888;
int neo_r = 0;
int neo_g = 0;
int neo_b = 0;

bool updateNeoPixel(false);

//converts the pin to an osc address
char * numToOSCAddress( int pin){
static char s[10];
int i = 9;
s[i–]= ‘\0’;
do
{
s[i] = “0123456789”[pin % 10];
–i;
pin /= 10;
}
while(pin && i);
s[i] = ‘/’;
return &s[i];
}

void sendColorSettingsToNeoPixel(){
for(int i=0;i<NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(neo_r, neo_g ,neo_b)); // Moderately bright green color.
}
updateNeoPixel = false;
pixels.show(); // This sends the updated pixel color to the hardware.
}

void setSinglePixel(OSCMessage &msg){
int setPixelNo(-1);
if (msg.isInt(0)){
setPixelNo = msg.getInt(0);
} //otherwise it’s a floating point frequency in Hz
else if(msg.isFloat(0)){
setPixelNo = msg.getFloat(0);
}
if(setPixelNo != -1)
pixels.setPixelColor(setPixelNo, pixels.Color(neo_r, neo_g ,neo_b));

updateNeoPixel = false;
pixels.show(); // This sends the updated pixel color to the hardware.
}

void routeRed(OSCMessage &msg ){
if (msg.isInt(0)){
neo_r = msg.getInt(0);
Serial.print(“/red: “);
Serial.println(neo_r);
} //otherwise it’s a floating point frequency in Hz
else if(msg.isFloat(0)){
neo_r = msg.getFloat(0);
Serial.print(“/red: “);
Serial.println(neo_r);
}
}

void pushRed(OSCMessage &msg ){
if (msg.isInt(0)){
neo_r = msg.getInt(0);
Serial.print(“/red: “);
Serial.println(neo_r);
} //otherwise it’s a floating point frequency in Hz
else if(msg.isFloat(0)){
neo_r = msg.getFloat(0);
Serial.print(“/red: “);
Serial.println(neo_r);
}
updateNeoPixel = true;
}

void routeGreen(OSCMessage &msg ){
if (msg.isInt(0)){
neo_g = msg.getInt(0);
Serial.print(“/green: “);
Serial.println(neo_g);
} //otherwise it’s a floating point frequency in Hz
else if(msg.isFloat(0)){
neo_g = msg.getFloat(0);
Serial.print(“/green: “);
Serial.println(neo_g);
}
}

void pushGreen(OSCMessage &msg ){
if (msg.isInt(0)){
neo_g = msg.getInt(0);
Serial.print(“/green: “);
Serial.println(neo_g);
} //otherwise it’s a floating point frequency in Hz
else if(msg.isFloat(0)){
neo_g = msg.getFloat(0);
Serial.print(“/green: “);
Serial.println(neo_g);
}
updateNeoPixel = true;
}

void routeBlue(OSCMessage &msg ){
if (msg.isInt(0)){
neo_b = msg.getInt(0);
Serial.print(“/blue: “);
Serial.println(neo_b);
} //otherwise it’s a floating point frequency in Hz
else if(msg.isFloat(0)){
neo_b = msg.getFloat(0);
Serial.print(“/blue: “);
Serial.println(neo_b);
}
}

void pushBlue(OSCMessage &msg ){
if (msg.isInt(0)){
neo_b = msg.getInt(0);
Serial.print(“/blue: “);
Serial.println(neo_b);
} //otherwise it’s a floating point frequency in Hz
else if(msg.isFloat(0)){
neo_b = msg.getFloat(0);
Serial.print(“/blue: “);
Serial.println(neo_b);
}
updateNeoPixel = true;
}

void execute(OSCMessage &msg ){

updateNeoPixel = true;
}

void allDark(OSCMessage &msg ){

for(int i=0;i<NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0, 0 ,0)); // Moderately bright green color.
}
updateNeoPixel = false;
pixels.show(); // This sends the updated pixel color to the hardware.
}

void doNothing(OSCMessage &msg ){

}

void setup() {
//setup ethernet part
Serial.begin(19200);
Ethernet.begin(mac,ip);
Udp.begin(inPort);
pixels.begin(); // This initializes the NeoPixel library.
}

//reads and dispatches the incoming message
void loop(){
OSCBundle bundleIN;
int size;
if( (size = Udp.parsePacket())>0)
{
while(size–)
bundleIN.fill(Udp.read());
if(!bundleIN.hasError()){
bundleIN.dispatch(“/red”, pushRed);
bundleIN.dispatch(“/green”, pushGreen);
bundleIN.dispatch(“/blue”, pushBlue);
bundleIN.dispatch(“/setRed”, routeRed);
bundleIN.dispatch(“/setGreen”, routeGreen);
bundleIN.dispatch(“/setBlue”, routeBlue);
bundleIN.dispatch(“/exec”, execute);
bundleIN.dispatch(“/allDark”, allDark);
bundleIN.dispatch(“/setSingle”, setSinglePixel);
}
}
if(updateNeoPixel)
{
sendColorSettingsToNeoPixel();
}
}

      About incalcando
      Related Posts
      • All
      • By Author
      • By Category

      Leave a Reply

      Your email address will not be published.