blynk & neopixelring & w7500
Dependencies: BlynkNeopixelW7500 Blynk_Example_WIZwiki-W7500 WIZnetInterface_ WS2812 mbed
Fork of Blynk_Example_WIZwiki-W7500 by
main.cpp
00001 /************************************************************* 00002 Download latest Blynk library here: 00003 https://github.com/blynkkk/blynk-library/releases/latest 00004 Blynk is a platform with iOS and Android apps to control 00005 Arduino, Raspberry Pi and the likes over the Internet. 00006 You can easily build graphic interfaces for all your 00007 projects by simply dragging and dropping widgets. 00008 Downloads, docs, tutorials: http://www.blynk.cc 00009 Sketch generator: http://examples.blynk.cc 00010 Blynk community: http://community.blynk.cc 00011 Social networks: http://www.fb.com/blynkapp 00012 http://twitter.com/blynk_app 00013 Blynk library is licensed under MIT license 00014 This example code is in public domain. 00015 ************************************************************* 00016 This example shows how to use Arduino.org Ethernet Shield 2 (W5500) 00017 to connect your project to Blynk. 00018 NOTE: You may have to install Arduino.ORG IDE to get it working: 00019 http://www.arduino.org/software 00020 Pins 10, 11, 12 and 13 are reserved for Ethernet module. 00021 DON'T use them in your sketch directly! 00022 Feel free to apply it to any other example. It's simple! 00023 *************************************************************/ 00024 00025 /* Comment this out to disable prints and save space */ 00026 #define BLYNK_PRINT Serial 00027 #define WS2812_BUF 8 00028 00029 #include "WS2812.h" 00030 #include "mbed.h" 00031 #include <SPI.h> 00032 #include "EthernetInterface.h" 00033 #include <BlynkSimpleEthernet2.h> 00034 00035 WS2812 ws(D2, WS2812_BUF, 0, 1, 1, 0); 00036 00037 void getBuf(int buf[], int NUM, uint8_t r, uint8_t g, uint8_t b); 00038 uint32_t Wheel(uint8_t WheelPos); 00039 00040 // You should get Auth Token in the Blynk App. 00041 // Go to the Project Settings (nut icon). 00042 char auth[] = "5f3177d2555a42188845f99ebc0d76ad"; 00043 00044 int colorbuf[WS2812_BUF]; 00045 int offbuf[WS2812_BUF]; 00046 00047 BLYNK_WRITE(V0) 00048 { 00049 int d = param.asInt(); 00050 printf("on/off button value : %d\r\n", d); 00051 if(d==0) ws.write(colorbuf); 00052 else ws.write(offbuf); 00053 } 00054 00055 BLYNK_WRITE(V1) 00056 { 00057 int d = param.asInt(); 00058 printf("brightness value : %d\r\n", d); 00059 ws.useII(WS2812::GLOBAL); 00060 ws.setII(d); 00061 ws.write(colorbuf); 00062 } 00063 00064 BLYNK_WRITE(V2) 00065 { 00066 int r = param[0].asInt(); 00067 int g = param[1].asInt(); 00068 int b = param[2].asInt(); 00069 printf("rgb value : %d %d %d\r\n", r, g, b); 00070 getBuf(colorbuf, WS2812_BUF, (uint8_t)r, (uint8_t)g, (uint8_t)b); 00071 ws.write(colorbuf); 00072 } 00073 00074 BLYNK_WRITE(V3) 00075 { 00076 int d = param.asInt(); 00077 printf("rainbow button value : %d\r\n", d); 00078 if(d){ 00079 for(int j=0; j<256*5; j++) { 00080 for(int i=0; i< WS2812_BUF; i++) { 00081 colorbuf[i]=Wheel(((i * 256 / WS2812_BUF) + j) & 255); 00082 } 00083 ws.write(colorbuf); 00084 wait_ms(20); 00085 } 00086 } 00087 } 00088 00089 00090 int main(void) { 00091 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0xff, 0xff, 0x48}; 00092 printf("Hello\r\n"); 00093 getBuf(offbuf, WS2812_BUF, 0x00, 0x00, 0x00); 00094 getBuf(colorbuf, WS2812_BUF, 0xff, 0xff, 0xff); 00095 00096 Blynk.begin(auth, "blynk-cloud.com", 8442, mac_addr); 00097 printf("Blynk init!\r\n"); 00098 while(1){ 00099 Blynk.run(); 00100 } 00101 } 00102 00103 void getBuf(int buf[], int NUM, uint8_t r, uint8_t g, uint8_t b){ 00104 for(int i=0; i<NUM; i++) { 00105 buf[i]=0; 00106 buf[i] |= (r<<16 & 0xff0000); 00107 buf[i] |= (g<<8 & 0x00ff00); 00108 buf[i] |= (b & 0x0000ff); 00109 } 00110 } 00111 00112 //255가지의 색을 나타내는 함수 00113 uint32_t Wheel(uint8_t WheelPos) { 00114 uint32_t data; 00115 if(WheelPos < 85) { 00116 data=(((WheelPos * 3)<<16) & 0xff0000) | (((255 - WheelPos * 3)<<8) & 0x00ff00 ) | (0 & 0x0000ff); 00117 } 00118 00119 else if(WheelPos < 170) { 00120 WheelPos -= 85; 00121 data= (((255-WheelPos * 3)<<16) & 0xff0000)| ((0<<8) & 0x00ff00 ) | ((WheelPos * 3) & 0x0000ff); 00122 } 00123 00124 else { 00125 WheelPos -= 170; 00126 data= ((0<<16) & 0xff0000)| (((WheelPos * 3)<<8) & 0x00ff00 ) | ((255-WheelPos * 3) & 0x0000ff); 00127 } 00128 return data; 00129 }
Generated on Thu Jul 14 2022 12:48:23 by 1.7.2