Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OSCMessage.h>
- #include <SLIPEncodedSerial.h>
- // these two includes are enough for our purpose
- // we don't have to import the whole OSC library
- #include <FastLED.h>
- #define NUM_LEDS 60
- #define DATA_PIN 3
- #define BAUDRATE 57600
- // 9600 is too slow
- //sets up an array that can be manipulated to set/clear data.
- CRGB leds [NUM_LEDS];
- SLIPEncodedSerial SLIPSerial(Serial);
- int analogValue = 0;
- long oldTime = 0;
- long newTime = 0;
- //tells the library that there is a strand of WS2812 leds on pin 3 and
- //that they will use the "leds" array and that there are 60 leds
- void setup()
- {
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- pinMode(13, OUTPUT);
- SLIPSerial.begin(BAUDRATE);
- }
- //
- void loop()
- {
- //send LED values to led
- static int led0; //led button 0
- static int led1; //led button 1
- static int led2; //led button 2
- FastLED.clear();
- ////////// testing single LED on/off::
- {
- if (led0 == 1)
- {
- leds[0] = CHSV( 224, 187, 150);
- }
- if (led0 == 0)
- {
- leds[0] = CHSV( 0, 0, 0);
- }
- }
- {
- if (led1 == 1)
- {
- leds[1] = CHSV( 80, 187, 150);
- }
- if (led1 == 0)
- {
- leds[1] = CHSV( 0, 0, 0);
- }
- }
- {
- if (led2 == 1)
- {
- leds[2] = CHSV( 140, 187, 150);
- }
- if (led2 == 0)
- {
- leds[2] = CHSV( 0, 0, 0);
- }
- }
- //////////
- // look for incoming OSC messages:
- // first check if bytes are available
- while(SLIPSerial.available())
- {
- // create empty OSC Message
- OSCMessage msg;
- // fill OSC message with incoming bytes till you reach end of packet //
- while(!SLIPSerial.endofPacket())
- {
- int size = SLIPSerial.available();
- while (size--)
- {
- msg.fill(SLIPSerial.read());
- }
- }
- ////test individual OSC receives
- if (msg.fullMatch("/ld0", 0))
- {
- // then check if first item is an integer
- if (msg.isInt(0))
- {
- // use the integer argument for controlling the led 0
- led0 = (msg.getInt(0));
- }
- Serial.println (led0);
- }
- if (msg.fullMatch("/ld1", 0))
- {
- // then check if first item is an integer
- if (msg.isInt(0))
- {
- // use the integer argument for controlling led 1
- led1 = (msg.getInt(0));
- }
- Serial.println (led1);
- }
- if (msg.fullMatch("/ld2", 0))
- {
- // then check if first item is an integer
- if (msg.isInt(0))
- {
- // use the integer argument for controlling led 1
- led2 = (msg.getInt(0));
- }
- Serial.println (led2);
- }
- FastLED.show();
- }
- }
Add Comment
Please, Sign In to add comment