blynk & neopixelring & w7500
Dependencies: BlynkNeopixelW7500 Blynk_Example_WIZwiki-W7500 WIZnetInterface_ WS2812 mbed
Fork of Blynk_Example_WIZwiki-W7500 by
main.cpp@3:523ddb62698b, 2017-11-28 (annotated)
- Committer:
- jcm931213
- Date:
- Tue Nov 28 00:49:57 2017 +0000
- Revision:
- 3:523ddb62698b
- Parent:
- 2:270491d6e155
Blynk NeoPixelRing w7500
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jcm931213 | 0:decc160be69d | 1 | /************************************************************* |
jcm931213 | 0:decc160be69d | 2 | Download latest Blynk library here: |
jcm931213 | 0:decc160be69d | 3 | https://github.com/blynkkk/blynk-library/releases/latest |
jcm931213 | 0:decc160be69d | 4 | Blynk is a platform with iOS and Android apps to control |
jcm931213 | 0:decc160be69d | 5 | Arduino, Raspberry Pi and the likes over the Internet. |
jcm931213 | 0:decc160be69d | 6 | You can easily build graphic interfaces for all your |
jcm931213 | 0:decc160be69d | 7 | projects by simply dragging and dropping widgets. |
jcm931213 | 0:decc160be69d | 8 | Downloads, docs, tutorials: http://www.blynk.cc |
jcm931213 | 0:decc160be69d | 9 | Sketch generator: http://examples.blynk.cc |
jcm931213 | 0:decc160be69d | 10 | Blynk community: http://community.blynk.cc |
jcm931213 | 0:decc160be69d | 11 | Social networks: http://www.fb.com/blynkapp |
jcm931213 | 0:decc160be69d | 12 | http://twitter.com/blynk_app |
jcm931213 | 0:decc160be69d | 13 | Blynk library is licensed under MIT license |
jcm931213 | 0:decc160be69d | 14 | This example code is in public domain. |
jcm931213 | 0:decc160be69d | 15 | ************************************************************* |
jcm931213 | 0:decc160be69d | 16 | This example shows how to use Arduino.org Ethernet Shield 2 (W5500) |
jcm931213 | 0:decc160be69d | 17 | to connect your project to Blynk. |
jcm931213 | 0:decc160be69d | 18 | NOTE: You may have to install Arduino.ORG IDE to get it working: |
jcm931213 | 0:decc160be69d | 19 | http://www.arduino.org/software |
jcm931213 | 0:decc160be69d | 20 | Pins 10, 11, 12 and 13 are reserved for Ethernet module. |
jcm931213 | 0:decc160be69d | 21 | DON'T use them in your sketch directly! |
jcm931213 | 0:decc160be69d | 22 | Feel free to apply it to any other example. It's simple! |
jcm931213 | 0:decc160be69d | 23 | *************************************************************/ |
jcm931213 | 0:decc160be69d | 24 | |
jcm931213 | 0:decc160be69d | 25 | /* Comment this out to disable prints and save space */ |
jcm931213 | 0:decc160be69d | 26 | #define BLYNK_PRINT Serial |
jcm931213 | 2:270491d6e155 | 27 | #define WS2812_BUF 8 |
jcm931213 | 0:decc160be69d | 28 | |
jcm931213 | 2:270491d6e155 | 29 | #include "WS2812.h" |
jcm931213 | 0:decc160be69d | 30 | #include "mbed.h" |
jcm931213 | 0:decc160be69d | 31 | #include <SPI.h> |
jcm931213 | 0:decc160be69d | 32 | #include "EthernetInterface.h" |
jcm931213 | 0:decc160be69d | 33 | #include <BlynkSimpleEthernet2.h> |
jcm931213 | 0:decc160be69d | 34 | |
jcm931213 | 2:270491d6e155 | 35 | WS2812 ws(D2, WS2812_BUF, 0, 1, 1, 0); |
jcm931213 | 0:decc160be69d | 36 | |
jcm931213 | 2:270491d6e155 | 37 | void getBuf(int buf[], int NUM, uint8_t r, uint8_t g, uint8_t b); |
jcm931213 | 2:270491d6e155 | 38 | uint32_t Wheel(uint8_t WheelPos); |
jcm931213 | 0:decc160be69d | 39 | |
jcm931213 | 0:decc160be69d | 40 | // You should get Auth Token in the Blynk App. |
jcm931213 | 0:decc160be69d | 41 | // Go to the Project Settings (nut icon). |
jcm931213 | 2:270491d6e155 | 42 | char auth[] = "5f3177d2555a42188845f99ebc0d76ad"; |
jcm931213 | 2:270491d6e155 | 43 | |
jcm931213 | 2:270491d6e155 | 44 | int colorbuf[WS2812_BUF]; |
jcm931213 | 2:270491d6e155 | 45 | int offbuf[WS2812_BUF]; |
jcm931213 | 2:270491d6e155 | 46 | |
jcm931213 | 2:270491d6e155 | 47 | BLYNK_WRITE(V0) |
jcm931213 | 2:270491d6e155 | 48 | { |
jcm931213 | 2:270491d6e155 | 49 | int d = param.asInt(); |
jcm931213 | 2:270491d6e155 | 50 | printf("on/off button value : %d\r\n", d); |
jcm931213 | 2:270491d6e155 | 51 | if(d==0) ws.write(colorbuf); |
jcm931213 | 2:270491d6e155 | 52 | else ws.write(offbuf); |
jcm931213 | 2:270491d6e155 | 53 | } |
jcm931213 | 2:270491d6e155 | 54 | |
jcm931213 | 2:270491d6e155 | 55 | BLYNK_WRITE(V1) |
jcm931213 | 2:270491d6e155 | 56 | { |
jcm931213 | 2:270491d6e155 | 57 | int d = param.asInt(); |
jcm931213 | 2:270491d6e155 | 58 | printf("brightness value : %d\r\n", d); |
jcm931213 | 2:270491d6e155 | 59 | ws.useII(WS2812::GLOBAL); |
jcm931213 | 2:270491d6e155 | 60 | ws.setII(d); |
jcm931213 | 2:270491d6e155 | 61 | ws.write(colorbuf); |
jcm931213 | 2:270491d6e155 | 62 | } |
jcm931213 | 0:decc160be69d | 63 | |
jcm931213 | 2:270491d6e155 | 64 | BLYNK_WRITE(V2) |
jcm931213 | 2:270491d6e155 | 65 | { |
jcm931213 | 2:270491d6e155 | 66 | int r = param[0].asInt(); |
jcm931213 | 2:270491d6e155 | 67 | int g = param[1].asInt(); |
jcm931213 | 2:270491d6e155 | 68 | int b = param[2].asInt(); |
jcm931213 | 2:270491d6e155 | 69 | printf("rgb value : %d %d %d\r\n", r, g, b); |
jcm931213 | 2:270491d6e155 | 70 | getBuf(colorbuf, WS2812_BUF, (uint8_t)r, (uint8_t)g, (uint8_t)b); |
jcm931213 | 2:270491d6e155 | 71 | ws.write(colorbuf); |
jcm931213 | 2:270491d6e155 | 72 | } |
jcm931213 | 0:decc160be69d | 73 | |
jcm931213 | 2:270491d6e155 | 74 | BLYNK_WRITE(V3) |
jcm931213 | 2:270491d6e155 | 75 | { |
jcm931213 | 2:270491d6e155 | 76 | int d = param.asInt(); |
jcm931213 | 2:270491d6e155 | 77 | printf("rainbow button value : %d\r\n", d); |
jcm931213 | 3:523ddb62698b | 78 | if(d){ |
jcm931213 | 2:270491d6e155 | 79 | for(int j=0; j<256*5; j++) { |
jcm931213 | 2:270491d6e155 | 80 | for(int i=0; i< WS2812_BUF; i++) { |
jcm931213 | 2:270491d6e155 | 81 | colorbuf[i]=Wheel(((i * 256 / WS2812_BUF) + j) & 255); |
jcm931213 | 2:270491d6e155 | 82 | } |
jcm931213 | 2:270491d6e155 | 83 | ws.write(colorbuf); |
jcm931213 | 2:270491d6e155 | 84 | wait_ms(20); |
jcm931213 | 2:270491d6e155 | 85 | } |
jcm931213 | 2:270491d6e155 | 86 | } |
jcm931213 | 2:270491d6e155 | 87 | } |
jcm931213 | 0:decc160be69d | 88 | |
jcm931213 | 0:decc160be69d | 89 | |
jcm931213 | 0:decc160be69d | 90 | int main(void) { |
jcm931213 | 2:270491d6e155 | 91 | uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0xff, 0xff, 0x48}; |
jcm931213 | 0:decc160be69d | 92 | printf("Hello\r\n"); |
jcm931213 | 2:270491d6e155 | 93 | getBuf(offbuf, WS2812_BUF, 0x00, 0x00, 0x00); |
jcm931213 | 2:270491d6e155 | 94 | getBuf(colorbuf, WS2812_BUF, 0xff, 0xff, 0xff); |
jcm931213 | 1:030843f74e27 | 95 | |
jcm931213 | 2:270491d6e155 | 96 | Blynk.begin(auth, "blynk-cloud.com", 8442, mac_addr); |
jcm931213 | 0:decc160be69d | 97 | printf("Blynk init!\r\n"); |
jcm931213 | 0:decc160be69d | 98 | while(1){ |
jcm931213 | 1:030843f74e27 | 99 | Blynk.run(); |
jcm931213 | 0:decc160be69d | 100 | } |
jcm931213 | 2:270491d6e155 | 101 | } |
jcm931213 | 2:270491d6e155 | 102 | |
jcm931213 | 2:270491d6e155 | 103 | void getBuf(int buf[], int NUM, uint8_t r, uint8_t g, uint8_t b){ |
jcm931213 | 2:270491d6e155 | 104 | for(int i=0; i<NUM; i++) { |
jcm931213 | 2:270491d6e155 | 105 | buf[i]=0; |
jcm931213 | 2:270491d6e155 | 106 | buf[i] |= (r<<16 & 0xff0000); |
jcm931213 | 2:270491d6e155 | 107 | buf[i] |= (g<<8 & 0x00ff00); |
jcm931213 | 2:270491d6e155 | 108 | buf[i] |= (b & 0x0000ff); |
jcm931213 | 2:270491d6e155 | 109 | } |
jcm931213 | 2:270491d6e155 | 110 | } |
jcm931213 | 2:270491d6e155 | 111 | |
jcm931213 | 2:270491d6e155 | 112 | //255가지의 색을 나타내는 함수 |
jcm931213 | 2:270491d6e155 | 113 | uint32_t Wheel(uint8_t WheelPos) { |
jcm931213 | 2:270491d6e155 | 114 | uint32_t data; |
jcm931213 | 2:270491d6e155 | 115 | if(WheelPos < 85) { |
jcm931213 | 2:270491d6e155 | 116 | data=(((WheelPos * 3)<<16) & 0xff0000) | (((255 - WheelPos * 3)<<8) & 0x00ff00 ) | (0 & 0x0000ff); |
jcm931213 | 2:270491d6e155 | 117 | } |
jcm931213 | 2:270491d6e155 | 118 | |
jcm931213 | 2:270491d6e155 | 119 | else if(WheelPos < 170) { |
jcm931213 | 2:270491d6e155 | 120 | WheelPos -= 85; |
jcm931213 | 2:270491d6e155 | 121 | data= (((255-WheelPos * 3)<<16) & 0xff0000)| ((0<<8) & 0x00ff00 ) | ((WheelPos * 3) & 0x0000ff); |
jcm931213 | 2:270491d6e155 | 122 | } |
jcm931213 | 2:270491d6e155 | 123 | |
jcm931213 | 2:270491d6e155 | 124 | else { |
jcm931213 | 2:270491d6e155 | 125 | WheelPos -= 170; |
jcm931213 | 2:270491d6e155 | 126 | data= ((0<<16) & 0xff0000)| (((WheelPos * 3)<<8) & 0x00ff00 ) | ((255-WheelPos * 3) & 0x0000ff); |
jcm931213 | 2:270491d6e155 | 127 | } |
jcm931213 | 2:270491d6e155 | 128 | return data; |
jcm931213 | 0:decc160be69d | 129 | } |