Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************
- * Blynk is a platform with iOS and Android apps to control
- * Arduino, Raspberry Pi and the likes over the Internet.
- * You can easily build graphic interfaces for all your
- * projects by simply dragging and dropping widgets.
- *
- * Downloads, docs, tutorials: http://www.blynk.cc
- * Blynk community: http://community.blynk.cc
- * Social networks: http://www.fb.com/blynkapp
- * http://twitter.com/blynk_app
- *
- * Blynk library is licensed under MIT license
- * This example code is in public domain.
- *
- **************************************************************
- * Control the IOT Ambilight Speaker.
- * Edited by PerfectPixel (www.instructables.com/member/perfectpixel
- *
- * For this example you need NeoPixel library:
- * https://github.com/adafruit/Adafruit_NeoPixel
- * You will also need any other libraries required for the internet interface you are choosing to use.
- *
- * App dashboard setup:
- * Large Slider Widget (0 - 500) on V1 called Color
- * Button Widget (push) on V2 called Cycle
- * Button Widget (push) on V3 called Rainbow
- * Button Widget (push) on V4 called Solid
- * Button Widget (push) on V5 called Off
- * Large Slider Widget (2-10) on V10 called Speed
- *
- **************************************************************/
- #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
- #include <BlynkSimpleUIPEthernet.h>
- #include <Adafruit_NeoPixel.h>
- int colordelay = 0;
- int shift = 0;
- #define PIN 3 //THE PIN THE NEOPIXEL's ARE CONNECTED TO
- int mode = 0; //1 = rainbow cycle, 2 = rainbow, 3 = solid color
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_RGB + NEO_KHZ800);
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "YOUR AUTH TOKEN HERE";
- void setup(){
- Blynk.begin(auth);
- strip.begin();
- strip.show();
- }
- BLYNK_WRITE(V2)
- {
- mode = 1; //RAINBOW CYCLE
- }
- BLYNK_WRITE(V3)
- {
- mode = 2; //RAINBOW
- }
- BLYNK_WRITE(V4)
- {
- mode = 3; //SOLID
- }
- BLYNK_WRITE(V5)
- {
- mode = 0; //OFF
- }
- BLYNK_WRITE(V1)
- {
- shift = param.asInt(); //Get the color from the slider
- }
- BLYNK_WRITE(V10)
- {
- colordelay = param.asInt(); //Get the speed from the slider
- }
- void loop()
- {
- Blynk.run();
- if(mode == 0){ //activitating the off button will ovveride all other colors
- colorWipe(strip.Color(0, 0, 0), 1);
- }
- else if(mode == 3){
- for (int i = 0; i < strip.numPixels(); i++)
- {
- strip.setPixelColor(i, Wheel(shift & 255));
- // OR: strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + shift) & 255));
- }
- strip.show();
- } else if(mode == 2){
- for(int j=0; j<256; j++) {
- for(int i=0; i<strip.numPixels(); i++) {
- strip.setPixelColor(i, Wheel((i+j) & 255));
- }
- strip.show();
- delay(colordelay);
- }
- } else if(mode == 1){
- for(int j=0; j<256; j++) { // 5 cycles of all colors on wheel
- for(int i=0; i< strip.numPixels(); i++) {
- strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
- }
- strip.show();
- delay(colordelay);
- }
- }
- }
- // Input a value 0 to 255 to get a color value.
- // The colours are a transition r - g - b - back to r.
- uint32_t Wheel(byte WheelPos) {
- if (WheelPos < 85) {
- return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
- } else if (WheelPos < 170) {
- WheelPos -= 85;
- return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
- } else {
- WheelPos -= 170;
- return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
- }
- }
- void colorWipe(uint32_t c, uint8_t wait) {
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- strip.setPixelColor(i, c);
- strip.show();
- delay(3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement