I am trying to send from max msp some values. I have no problem in receiving them however, when I try to send multiple values at one I have some troubles. Is there a way to get multiple values?
using the code below I am getting :
pixelNum:
10
pixelState:
0
pixelNum:
1
pixelState:
0
void loop() {
OSCMessage msgIN;
int size;
if((size = Udp.parsePacket())>0){
while(size--)
msgIN.fill(Udp.read());
if(!msgIN.hasError()){
msgIN.route("/pixelAni",pixelAni);
}
}
}
void pixelAni(OSCMessage &msg, int addrOffset){
int pixelNum = msg.getInt(0);
int pixelState = msg.getInt(1);
Serial.println("pixelNum: ");
Serial.println(pixelNum);
Serial.println("pixelState: ");
Serial.println(pixelState);
pixels[pixelNum].R = 255;
pixels[pixelNum].G = 255;
pixels[pixelNum].B = 255;
ledstrip.show(pixels);
}
here the code:
#include <ws2812_i2s.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCBundle.h>
#define NUM_LEDS 158
char ssid[] = "TP-LINK_D44190"; // your network SSID (name)
char pass[] = "67966325"; // your network password
WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP
const unsigned int localPort = 8000; // local port to listen for UDP packets at the NodeMCU (another device must send OSC messages to this port)
const unsigned int destPort = 9000; // remote port of the target device where the NodeMCU sends OSC to
static WS2812 ledstrip;
static Pixel_t pixels[NUM_LEDS];
//GLOBAL VALUES
int globalR = 255;
int globalG = 255;
int globalB = 255;
int clickedPixel = 0;
void setup() {
Serial.begin(115200);
// If you erase this line, your ESP8266 will get a dynamic IP address
WiFi.config(IPAddress(192,168,0,123),IPAddress(192,168,0,1), IPAddress(255,255,255,0));
Serial.println();
Serial.println("LIVECT LAB LIGHTS");
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
Serial.println(Udp.localPort());
ledstrip.init(NUM_LEDS);
}
void loop() {
OSCMessage msgIN;
int size;
if((size = Udp.parsePacket())>0){
while(size--)
msgIN.fill(Udp.read());
if(!msgIN.hasError()){
msgIN.route("/allLEDonOff",allLEDonOff);
msgIN.route("/globalR",globalRVoid);
msgIN.route("/globalG",globalGVoid);
msgIN.route("/globalB",globalBVoid);
msgIN.route("/pixelAni",pixelAni);
msgIN.route("/pixelAniOnOff",pixelAniOnOff);
}
}
}
void pixelAni(OSCMessage &msg, int addrOffset){
int pixelNum = msg.getInt(0);
int pixelState = msg.getInt(1);
Serial.println("pixelNum: ");
Serial.println(pixelNum);
Serial.println("pixelState: ");
Serial.println(pixelState);
pixels[pixelNum].R = 255;
pixels[pixelNum].G = 255;
pixels[pixelNum].B = 255;
ledstrip.show(pixels);
}
void pixelAniOnOff(OSCMessage &msg, int addrOffset){
int i = msg.getInt(0);
if (i == 0) {
pixels[clickedPixel].R = globalR;
pixels[clickedPixel].G = globalG;
pixels[clickedPixel].B = globalB;
}
ledstrip.show(pixels);
}
void allLEDonOff(OSCMessage &msg, int addrOffset){
uint8_t i;
int ledState = msg.getInt(0);
//Serial.println(ledState);
if (ledState == 0) {
for(i=0; i<NUM_LEDS; i++) {
pixels[i].R = 0;
pixels[i].G = 0;
pixels[i].B = 0;
}
} else {
for(i=0; i<NUM_LEDS; i++) {
pixels[i].R = globalR;
pixels[i].G = globalG;
pixels[i].B = globalB;
}
}
//Serial.println(globalR);
ledstrip.show(pixels);
}
void globalRVoid(OSCMessage &msg, int addrOffset){
int ledState = msg.getInt(0);
globalR = ledState;
uint8_t i;
for(i=0; i<NUM_LEDS; i++) {
pixels[i].R = globalR;
}
ledstrip.show(pixels);
}
void globalGVoid(OSCMessage &msg, int addrOffset){
int ledState = msg.getInt(0);
globalG = ledState;
uint8_t i;
for(i=0; i<NUM_LEDS; i++) {
pixels[i].G = globalG;
}
ledstrip.show(pixels);
}
void globalBVoid(OSCMessage &msg, int addrOffset){
int ledState = msg.getInt(0);
globalB = ledState;
uint8_t i;
for(i=0; i<NUM_LEDS; i++) {
pixels[i].B = globalB;
}
ledstrip.show(pixels);
}
// end of file