Guest User

Untitled

a guest
Jun 8th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 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. //sets up an array that can be manipulated to set/clear data.
  14. CRGB leds [NUM_LEDS];
  15.  
  16. SLIPEncodedSerial SLIPSerial(Serial);
  17.  
  18. int analogValue = 0;
  19. long oldTime = 0;
  20. long newTime = 0;
  21.  
  22. //tells the library that there is a strand of WS2812 leds on pin 3 and
  23. //that they will use the "leds" array and that there are 60 leds
  24.  
  25.  
  26. void setup()
  27. {
  28.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  29.   pinMode(13, OUTPUT);
  30.   SLIPSerial.begin(BAUDRATE);
  31. }
  32.  
  33. //
  34.  
  35.  
  36. void loop()
  37. {
  38.  
  39.   //send LED values to led
  40.   static int led0; //led button 0
  41.   static int led1; //led button 1
  42.   static int led2; //led button 2
  43.  
  44.     FastLED.clear();
  45.  
  46.   //////////  testing single LED on/off::
  47.   {
  48.     if (led0 == 1)
  49.     {
  50.       leds[0] = CHSV( 224, 187, 150);
  51.     }
  52.  
  53.     if (led0 == 0)
  54.     {
  55.       leds[0] = CHSV( 0, 0, 0);
  56.     }
  57.   }
  58.  
  59.   {
  60.     if (led1 == 1)
  61.     {
  62.       leds[1] = CHSV( 80, 187, 150);  
  63.     }
  64.  
  65.     if (led1 == 0)
  66.     {
  67.       leds[1] = CHSV( 0, 0, 0);
  68.     }
  69.  
  70.   }
  71.  
  72.   {
  73.     if (led2 == 1)
  74.     {
  75.       leds[2] = CHSV( 140, 187, 150);  
  76.     }
  77.  
  78.     if (led2 == 0)
  79.     {
  80.       leds[2] = CHSV( 0, 0, 0);
  81.     }
  82.  
  83.   }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.   //////////
  90.  
  91.  
  92.   // look for incoming OSC messages:
  93.  
  94.   // first check if bytes are available
  95.   while(SLIPSerial.available())
  96.   {
  97.     // create empty OSC Message
  98.     OSCMessage msg;
  99.     // fill OSC message with incoming bytes till you reach end of packet //
  100.     while(!SLIPSerial.endofPacket())
  101.     {
  102.       int size = SLIPSerial.available();
  103.       while (size--)
  104.       {
  105.         msg.fill(SLIPSerial.read());
  106.       }
  107.     }    
  108.  
  109.  
  110.     ////test individual OSC receives      
  111.     if (msg.fullMatch("/ld0", 0))
  112.     {
  113.       // then check if first item is an integer
  114.       if (msg.isInt(0))
  115.       {
  116.         // use the integer argument for controlling the led 0
  117.         led0 = (msg.getInt(0));
  118.       }
  119.       Serial.println (led0);
  120.     }
  121.  
  122.     if (msg.fullMatch("/ld1", 0))
  123.     {
  124.       // then check if first item is an integer
  125.       if (msg.isInt(0))
  126.       {
  127.         // use the integer argument for controlling led 1
  128.         led1 = (msg.getInt(0));
  129.       }
  130.       Serial.println (led1);
  131.     }
  132.  
  133.     if (msg.fullMatch("/ld2", 0))
  134.     {
  135.       // then check if first item is an integer
  136.       if (msg.isInt(0))
  137.       {
  138.         // use the integer argument for controlling led 1
  139.         led2 = (msg.getInt(0));
  140.       }
  141.       Serial.println (led2);
  142.     }
  143.  
  144.  
  145.  
  146.  
  147.  
  148.     FastLED.show();
  149.   }
  150.  
  151. }
Add Comment
Please, Sign In to add comment