Guest User

Untitled

a guest
Jun 8th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <OSCMessage.h>
  2. #include <SLIPEncodedSerial.h>
  3. // these two includes are enough for our purpose
  4. // we don't have to import the whole OSC library
  5.  
  6. #include <FastLED.h>
  7. #define NUM_LEDS 60
  8. #define DATA_PIN 3
  9.  
  10. #define BAUDRATE 57600
  11. // 9600 is too slow
  12.  
  13. SLIPEncodedSerial SLIPSerial(Serial);
  14.  
  15. int analogValue = 0;
  16. long oldTime = 0;
  17. long newTime = 0;
  18.  
  19. CRGB leds[NUM_LEDS];
  20.  
  21. void setup()
  22. {
  23.   FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
  24.   pinMode(13, OUTPUT);
  25.   SLIPSerial.begin(BAUDRATE);
  26. }
  27.  
  28. void loop()
  29. {
  30.  
  31.   static int sendval;  
  32.  
  33.   //first clear the existing led values
  34.   FastLED.clear();
  35.   for(int led = 0; led < sendval; led++)
  36.   {
  37.     leds[led] = CRGB::Blue;
  38.   }
  39.  
  40.   // look for incoming OSC messages:
  41.  
  42.   // first check if bytes are available
  43.   while(SLIPSerial.available())
  44.   {
  45.     // create empty OSC Message
  46.     OSCMessage msg;
  47.     // fill OSC message with incoming bytes till you reach end of packet //
  48.     while(!SLIPSerial.endofPacket())
  49.     {
  50.       int size = SLIPSerial.available();
  51.       while (size--)
  52.       {
  53.         msg.fill(SLIPSerial.read());
  54.       }
  55.     }    
  56.  
  57.  
  58.  
  59.     // now check the address (to compare the full adress, set the second argument to 0)
  60.  
  61.     if (msg.fullMatch("/fad", 0))
  62.     {
  63.       // then check if first item is an integer
  64.       if (msg.isInt(0))
  65.       {
  66.         // use the integer argument for controlling the number of lit LEDs
  67.         sendval = (msg.getInt(0));
  68.       }
  69.       Serial.println (sendval);
  70.     }
  71.  
  72.  
  73.     FastLED.show();
  74.   }
  75.  
  76. }
Add Comment
Please, Sign In to add comment