Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. #define DATA_PIN 6
  4. //#define CLK_PIN 4
  5. #define LED_TYPE WS2811
  6. #define COLOR_ORDER GRB
  7. #define NUM_LEDS 270
  8. CRGB leds[NUM_LEDS];
  9.  
  10. #define FRAMES_PER_SECOND 120
  11.  
  12. byte serialIn;
  13.  
  14. void setup() {
  15. delay(100);
  16. // put your setup code here, to run once:
  17. FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  18. FastLED.setBrightness(255);
  19.  
  20. Serial.begin(115200);
  21.  
  22.  
  23. }
  24.  
  25. int serialPos = 0;
  26. long lastMessage;
  27.  
  28. byte inByte[4];
  29.  
  30. void loop() {
  31. // put your main code here, to run repeatedly:
  32.  
  33. for (int i = 0; i <= 90; i++) {
  34. leds[i].setRGB(inByte[0],0,0);
  35. }
  36. for (int i = 90; i <= 180; i++) {
  37. leds[i].setRGB(0,inByte[1],0);
  38. }
  39. for (int i = 180; i <= 270; i++) {
  40. leds[i].setRGB(0,0,inByte[2]);
  41. }
  42.  
  43. FastLED.show();
  44. //FastLED.delay(1000/FRAMES_PER_SECOND);
  45.  
  46.  
  47. if (Serial.available() > 0) {
  48. if (millis() - lastMessage > 20) { // New message start
  49. serialPos = 0;
  50. }
  51. inByte[serialPos] = Serial.read();
  52. serialPos ++;
  53. lastMessage = millis();
  54.  
  55. if (serialPos > 3) {
  56. serialPos = 3;
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement