blynk & neopixelring & w7500
Dependencies: BlynkNeopixelW7500 Blynk_Example_WIZwiki-W7500 WIZnetInterface_ WS2812 mbed
Fork of Blynk_Example_WIZwiki-W7500 by
Revision 2:270491d6e155, committed 2017-11-27
- Comitter:
- jcm931213
- Date:
- Mon Nov 27 11:50:09 2017 +0000
- Parent:
- 1:030843f74e27
- Child:
- 3:523ddb62698b
- Commit message:
- finish!!!!!
Changed in this revision
--- a/Blynk.lib Tue Sep 05 23:22:02 2017 +0000 +++ b/Blynk.lib Mon Nov 27 11:50:09 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/IOP/code/WIZwiki-7500_Blynk/#ba922c4e9aee +https://developer.mbed.org/teams/IOP/code/WIZwiki-7500_Blynk/#bc3d69c01bf2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Blynk_Example_WIZwiki-W7500111.lib Mon Nov 27 11:50:09 2017 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/teams/IOP/code/Blynk_Example_WIZwiki-W7500/#030843f74e27
--- a/WIZnetInterface.lib Tue Sep 05 23:22:02 2017 +0000 +++ b/WIZnetInterface.lib Mon Nov 27 11:50:09 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/IOP/code/WIZnetInterface/#1a89f410e1e4 +http://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/#206920aceb69
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WS2812.lib Mon Nov 27 11:50:09 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/bridadan/code/WS2812/#33b71af3ca0d
--- a/main.cpp Tue Sep 05 23:22:02 2017 +0000 +++ b/main.cpp Mon Nov 27 11:50:09 2017 +0000 @@ -24,32 +24,106 @@ /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial +#define WS2812_BUF 8 +#include "WS2812.h" #include "mbed.h" #include <SPI.h> #include "EthernetInterface.h" #include <BlynkSimpleEthernet2.h> +WS2812 ws(D2, WS2812_BUF, 0, 1, 1, 0); -EthernetInterface eth0; +void getBuf(int buf[], int NUM, uint8_t r, uint8_t g, uint8_t b); +uint32_t Wheel(uint8_t WheelPos); // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). -char auth[] = "f6e02fba337e45f19f9c51567323ea8d"; +char auth[] = "5f3177d2555a42188845f99ebc0d76ad"; + +int colorbuf[WS2812_BUF]; +int offbuf[WS2812_BUF]; + +BLYNK_WRITE(V0) +{ + int d = param.asInt(); + printf("on/off button value : %d\r\n", d); + if(d==0) ws.write(colorbuf); + else ws.write(offbuf); +} + +BLYNK_WRITE(V1) +{ + int d = param.asInt(); + printf("brightness value : %d\r\n", d); + ws.useII(WS2812::GLOBAL); + ws.setII(d); + ws.write(colorbuf); +} +BLYNK_WRITE(V2) +{ + int r = param[0].asInt(); + int g = param[1].asInt(); + int b = param[2].asInt(); + printf("rgb value : %d %d %d\r\n", r, g, b); + getBuf(colorbuf, WS2812_BUF, (uint8_t)r, (uint8_t)g, (uint8_t)b); + ws.write(colorbuf); +} +BLYNK_WRITE(V3) +{ + int d = param.asInt(); + printf("rainbow button value : %d\r\n", d); + while(d){ + for(int j=0; j<256*5; j++) { + for(int i=0; i< WS2812_BUF; i++) { + colorbuf[i]=Wheel(((i * 256 / WS2812_BUF) + j) & 255); + } + ws.write(colorbuf); + wait_ms(20); + } + } +} int main(void) { + uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0xff, 0xff, 0x48}; printf("Hello\r\n"); - uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0xff, 0xff, 0x25}; - eth0.init(mac_addr); - eth0.connect(); + getBuf(offbuf, WS2812_BUF, 0x00, 0x00, 0x00); + getBuf(colorbuf, WS2812_BUF, 0xff, 0xff, 0xff); - Blynk.begin(auth); - + Blynk.begin(auth, "blynk-cloud.com", 8442, mac_addr); printf("Blynk init!\r\n"); while(1){ Blynk.run(); } +} + +void getBuf(int buf[], int NUM, uint8_t r, uint8_t g, uint8_t b){ + for(int i=0; i<NUM; i++) { + buf[i]=0; + buf[i] |= (r<<16 & 0xff0000); + buf[i] |= (g<<8 & 0x00ff00); + buf[i] |= (b & 0x0000ff); + } +} + +//255가지의 색을 나타내는 함수 +uint32_t Wheel(uint8_t WheelPos) { + uint32_t data; + if(WheelPos < 85) { + data=(((WheelPos * 3)<<16) & 0xff0000) | (((255 - WheelPos * 3)<<8) & 0x00ff00 ) | (0 & 0x0000ff); + } + + else if(WheelPos < 170) { + WheelPos -= 85; + data= (((255-WheelPos * 3)<<16) & 0xff0000)| ((0<<8) & 0x00ff00 ) | ((WheelPos * 3) & 0x0000ff); + } + + else { + WheelPos -= 170; + data= ((0<<16) & 0xff0000)| (((WheelPos * 3)<<8) & 0x00ff00 ) | ((255-WheelPos * 3) & 0x0000ff); + } + return data; } \ No newline at end of file
--- a/mbed.bld Tue Sep 05 23:22:02 2017 +0000 +++ b/mbed.bld Mon Nov 27 11:50:09 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/e7ca05fa8600 \ No newline at end of file