Guest User

Untitled

a guest
Sep 11th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. CRGB leds[12];
  4. int MotionRead;
  5. int Motion;
  6. byte ledProgram;
  7. byte oldValue;
  8. unsigned long timer;
  9. unsigned long timer1;
  10. byte y;
  11.  
  12. void pulsingWhite();
  13. void rainbow();
  14. void solidWhite();
  15. void off();
  16.  
  17.  
  18. void setup() {
  19. FastLED.addLeds<WS2812B, 1>(leds, 12);
  20. //MotionRead = analogRead(1);
  21. //Motion = map(MotionRead, 0, 1023, 0, 255);
  22. //oldValue = Motion;
  23. }
  24.  
  25.  
  26. void loop() {
  27.  
  28. MotionRead = analogRead(1);
  29. Motion = map(MotionRead, 0, 1023, 0, 255);
  30.  
  31. solidWhite();
  32. if (Motion - oldValue > 15 || oldValue - Motion > 15) {
  33. oldValue = Motion;
  34. if (millis() > timer1 + 1000) {
  35. ledProgram++;
  36. timer1 = millis();
  37. if (ledProgram > 4)ledProgram = 0;
  38. }
  39. }
  40.  
  41.  
  42. switch (ledProgram) {
  43. case 0:
  44. {
  45. solidWhite();
  46. break;
  47. }
  48. case 1:
  49. {
  50. pulsingWhite();
  51. break;
  52. }
  53. case 2:
  54. {
  55. candle();
  56. break;
  57. }
  58. case 3:
  59. {
  60. rainbow();
  61. break;
  62. }
  63. case 4:
  64. {
  65. off();
  66. break;
  67. }
  68. }
  69. FastLED.show();
  70. }
  71.  
  72.  
  73. void solidWhite() {
  74. for (int x = 0; x < 12; x++) {
  75. leds[x] = CHSV(0, 0 , 255);
  76. }
  77. }
  78.  
  79. void pulsingWhite() {
  80. if (millis() > timer + 100) {
  81. y++;
  82. //if (y == 255)y = 0;
  83. timer = millis();
  84. }
  85. for (int x = 0; x < 12; x++) {
  86. leds[x] = CHSV(0, 0, y);
  87. }
  88. }
  89.  
  90.  
  91. void candle() {
  92. if (millis() > timer + 400) {
  93. for (int x = 0; x < 12; x++) {
  94. y = random8();
  95. leds[x] = CHSV(0, 0, 255 - y);
  96. }
  97. timer = millis();
  98. }
  99. }
  100.  
  101. void rainbow() {
  102. if (millis() > timer + 100) {
  103. y++;
  104. //if (y == 255)y = 0;
  105. timer = millis();
  106. }
  107. for (int x = 0; x < 12; x++) {
  108. leds[x] = CHSV(y, 255, 255);
  109. }
  110. }
  111.  
  112.  
  113. void off() {
  114. for (int x = 0; x < 12; x++) {
  115. leds[x] = CHSV(0, 0, 0);
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment