Displays a gradient between two colors
Dependencies: mbed WS2812 PixelArray
Revision 1:3fa4e131f518, committed 2021-04-19
- Comitter:
- radmir102
- Date:
- Mon Apr 19 12:08:45 2021 +0000
- Parent:
- 0:3bb97062a703
- Child:
- 2:c4a43cc93ca8
- Commit message:
- The program was created for the matrix 4x4 Olympiad for schoolchildren
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Mar 12 23:02:59 2017 +0000
+++ b/main.cpp Mon Apr 19 12:08:45 2021 +0000
@@ -2,14 +2,19 @@
#include "WS2812.h"
#include "PixelArray.h"
-#define WS2812_BUF 77 //number of LEDs in the array
-#define NUM_COLORS 2 //number of colors to store in the array
+#define WS2812_BUF 16 //number of LEDs in the array
+#define NUM_COLORS 6 //number of colors to store in the array
+#define PIN_NUM A2
+#define LIGHT_INTENSITY 30
+using namespace std;
DigitalOut usrLed(LED1);
PixelArray px(WS2812_BUF);
+DigitalIn usrBtn(USER_BUTTON);
+
// See the program page for information on the timing numbers
-WS2812 ws(D9, WS2812_BUF, 6,17,9,14); //nucleo-f411re
+WS2812 ws(PIN_NUM, WS2812_BUF,6,17,9,14); //nucleo-f411re
int color_set(uint8_t red,uint8_t green, uint8_t blue)
{
@@ -27,23 +32,24 @@
uint8_t ir = 0;
uint8_t ig = 0;
uint8_t ib = 0;
+ int btnState = 0;
ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling
// set up the colours we want to draw with
- int colorbuf[NUM_COLORS] = {0xff0000,0x0000ff};
+ int colorbuf[NUM_COLORS] = {0xff0000,0x0000ff,0x0002f0,0x00002f,0x00002f,0x2f002f};
//get starting RGB components for interpolation
- std::size_t c1 = colorbuf[0];
- std::size_t r1 = (c1 & 0xff0000) >> 16;
- std::size_t g1 = (c1 & 0x00ff00) >> 8;
- std::size_t b1 = (c1 & 0x0000ff);
+ size_t c1 = colorbuf[0];
+ size_t r1 = (c1 & 0xff0000) >> 16;
+ size_t g1 = (c1 & 0x00ff00) >> 8;
+ size_t b1 = (c1 & 0x0000ff);
//get ending RGB components for interpolation
- std::size_t c2 = colorbuf[1];
- std::size_t r2 = (c2 & 0xff0000) >> 16;
- std::size_t g2 = (c2 & 0x00ff00) >> 8;
- std::size_t b2 = (c2 & 0x0000ff);
+ size_t c2 = colorbuf[1];
+ size_t r2 = (c2 & 0xff0000) >> 16;
+ size_t g2 = (c2 & 0x00ff00) >> 8;
+ size_t b2 = (c2 & 0x0000ff);
for (int i = 0; i <= WS2812_BUF; i++)
{
@@ -55,13 +61,86 @@
px.Set(i, color_set(ir,ig,ib));
//write the II value for each pixel
- px.SetI(i, 32);
+ /*px.SetI(4, 30);
+ px.SetI(1, 30);
+ px.SetI(2, 30);
+ px.SetI(7, 30);
+ px.SetI(12, 30);
+ px.SetI(15, 30);*/// смайлик убийца
+
+ px.SetI(i, 10);
+
+ /*px.SetI(10, 15);
+
+ px.SetI(15, 20);
+
+ px.SetI(3, 25);
+
+ px.SetI(6, 30);
+
+ px.SetI(9, 15);
+
+ px.SetI(12, 5);*/
+
}
-
+ /*
for (int i = WS2812_BUF; i >= 0; i--)
{
ws.write(px.getBuf());
- }
+ }*/
+
+ usrLed = 1;
+
+
+
- usrLed = 1;
+ /*
+ while (1)
+ {
+ if (usrBtn == 0) //button is pressed
+ {
+ //write the color value for each pixel
+ px.SetAll(colorbuf[btnState]);
+ //write the II value for each pixel
+ px.SetAllI(64);
+
+ usrLed = 1;
+ btnState = btnState++;
+
+ if (btnState == NUM_COLORS) {
+ btnState = 0;
+ }
+ }
+ else
+ {
+ px.SetAll(colorbuf[btnState]);
+ px.SetI(0, LIGHT_INTENSITY);
+
+ px.SetI(5, LIGHT_INTENSITY);
+
+ px.SetI(10, LIGHT_INTENSITY);
+
+ px.SetI(15, LIGHT_INTENSITY);
+
+ px.SetI(3, LIGHT_INTENSITY);
+
+ px.SetI(6, LIGHT_INTENSITY);
+
+ px.SetI(9, LIGHT_INTENSITY);
+
+ px.SetI(12, LIGHT_INTENSITY);
+
+ usrLed = 0;
+ }
+
+
+
+
+ for (int i = WS2812_BUF; i >= 0; i--)
+ {
+ ws.write(px.getBuf());
+ }
+
+ }*/
+
}