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
- SLIPEncodedSerial SLIPSerial(Serial);
- int analogValue = 0;
- long oldTime = 0;
- long newTime = 0;
- CRGB leds[NUM_LEDS];
- void setup()
- {
- FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
- pinMode(13, OUTPUT);
- SLIPSerial.begin(BAUDRATE);
- }
- void loop()
- {
- static int sendval;
- //first clear the existing led values
- FastLED.clear();
- for(int led = 0; led < sendval; led++)
- {
- leds[led] = CRGB::Blue;
- }
- // 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());
- }
- }
- // now check the address (to compare the full adress, set the second argument to 0)
- if (msg.fullMatch("/fad", 0))
- {
- // then check if first item is an integer
- if (msg.isInt(0))
- {
- // use the integer argument for controlling the number of lit LEDs
- sendval = (msg.getInt(0));
- }
- Serial.println (sendval);
- }
- FastLED.show();
- }
- }
Add Comment
Please, Sign In to add comment