Advertisement
Guest User

Untitled

a guest
Jan 20th, 2016
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. /**************************************************************
  2. * Blynk is a platform with iOS and Android apps to control
  3. * Arduino, Raspberry Pi and the likes over the Internet.
  4. * You can easily build graphic interfaces for all your
  5. * projects by simply dragging and dropping widgets.
  6. *
  7. * Downloads, docs, tutorials: http://www.blynk.cc
  8. * Blynk community: http://community.blynk.cc
  9. * Social networks: http://www.fb.com/blynkapp
  10. * http://twitter.com/blynk_app
  11. *
  12. * Blynk library is licensed under MIT license
  13. * This example code is in public domain.
  14. *
  15. **************************************************************
  16. * Control the IOT Ambilight Speaker.
  17. * Edited by PerfectPixel (www.instructables.com/member/perfectpixel
  18. *
  19. * For this example you need NeoPixel library:
  20. * https://github.com/adafruit/Adafruit_NeoPixel
  21. * You will also need any other libraries required for the internet interface you are choosing to use.
  22. *
  23. * App dashboard setup:
  24. * Large Slider Widget (0 - 500) on V1 called Color
  25. * Button Widget (push) on V2 called Cycle
  26. * Button Widget (push) on V3 called Rainbow
  27. * Button Widget (push) on V4 called Solid
  28. * Button Widget (push) on V5 called Off
  29. * Large Slider Widget (2-10) on V10 called Speed
  30. *
  31. **************************************************************/
  32. #include <UIPEthernet.h> //these libraries may be different if you are using a different interface (e.g. arduino wifi shield or the arduino ethernet shield
  33. #include <BlynkSimpleUIPEthernet.h>
  34. #include <Adafruit_NeoPixel.h>
  35.  
  36. int colordelay = 0;
  37. int shift = 0;
  38.  
  39. #define PIN 3 //THE PIN THE NEOPIXEL's ARE CONNECTED TO
  40.  
  41. int mode = 0; //1 = rainbow cycle, 2 = rainbow, 3 = solid color
  42.  
  43. Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_RGB + NEO_KHZ800);
  44.  
  45. // You should get Auth Token in the Blynk App.
  46. // Go to the Project Settings (nut icon).
  47. char auth[] = "YOUR AUTH TOKEN HERE";
  48.  
  49. void setup(){
  50.  
  51. Blynk.begin(auth);
  52. strip.begin();
  53. strip.show();
  54. }
  55. BLYNK_WRITE(V2)
  56. {
  57. mode = 1; //RAINBOW CYCLE
  58. }
  59. BLYNK_WRITE(V3)
  60. {
  61. mode = 2; //RAINBOW
  62. }
  63. BLYNK_WRITE(V4)
  64. {
  65. mode = 3; //SOLID
  66. }
  67. BLYNK_WRITE(V5)
  68. {
  69. mode = 0; //OFF
  70. }
  71. BLYNK_WRITE(V1)
  72. {
  73. shift = param.asInt(); //Get the color from the slider
  74. }
  75.  
  76. BLYNK_WRITE(V10)
  77. {
  78. colordelay = param.asInt(); //Get the speed from the slider
  79. }
  80.  
  81. void loop()
  82. {
  83. Blynk.run();
  84. if(mode == 0){ //activitating the off button will ovveride all other colors
  85.  
  86. colorWipe(strip.Color(0, 0, 0), 1);
  87. }
  88. else if(mode == 3){
  89.  
  90. for (int i = 0; i < strip.numPixels(); i++)
  91. {
  92. strip.setPixelColor(i, Wheel(shift & 255));
  93. // OR: strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + shift) & 255));
  94. }
  95. strip.show();
  96. } else if(mode == 2){
  97.  
  98. for(int j=0; j<256; j++) {
  99. for(int i=0; i<strip.numPixels(); i++) {
  100. strip.setPixelColor(i, Wheel((i+j) & 255));
  101. }
  102. strip.show();
  103. delay(colordelay);
  104. }
  105. } else if(mode == 1){
  106.  
  107. for(int j=0; j<256; j++) { // 5 cycles of all colors on wheel
  108. for(int i=0; i< strip.numPixels(); i++) {
  109. strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  110. }
  111. strip.show();
  112. delay(colordelay);
  113. }
  114. }
  115.  
  116. }
  117.  
  118.  
  119. // Input a value 0 to 255 to get a color value.
  120. // The colours are a transition r - g - b - back to r.
  121. uint32_t Wheel(byte WheelPos) {
  122. if (WheelPos < 85) {
  123. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  124. } else if (WheelPos < 170) {
  125. WheelPos -= 85;
  126. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  127. } else {
  128. WheelPos -= 170;
  129. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  130. }
  131. }
  132.  
  133. void colorWipe(uint32_t c, uint8_t wait) {
  134. for(uint16_t i=0; i<strip.numPixels(); i++) {
  135. strip.setPixelColor(i, c);
  136. strip.show();
  137. delay(3);
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement