Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: PixelArray WS2812 mbed
main.cpp
00001 #include "mbed.h" 00002 #include "WS2812.h" 00003 #include "PixelArray.h" 00004 00005 #define WS2812_BUF 77 //number of LEDs in the array 00006 #define NUM_COLORS 6 //number of colors to store in the array 00007 00008 DigitalIn usrBtn(USER_BUTTON); 00009 DigitalOut usrLed(LED1); 00010 PixelArray px(WS2812_BUF); 00011 00012 // See the program page for information on the timing numbers 00013 WS2812 ws(D9, WS2812_BUF, 6,17,9,14); //nucleo-f411re 00014 00015 int main() 00016 { 00017 int btnState = 0; 00018 00019 ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling 00020 00021 // set up the colours we want to draw with 00022 int colorbuf[NUM_COLORS] = {0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f}; 00023 00024 // Now the buffer is written, write it to the led array. 00025 while (1) 00026 { 00027 if (usrBtn == 0) //button is pressed 00028 { 00029 usrLed = 1; 00030 btnState = btnState++; 00031 00032 if (btnState == NUM_COLORS) { 00033 btnState = 0; 00034 } 00035 } 00036 else 00037 { 00038 usrLed = 0; 00039 } 00040 00041 //write the color value for each pixel 00042 px.SetAll(colorbuf[btnState]); 00043 00044 //write the II value for each pixel 00045 px.SetAllI(64); 00046 00047 for (int i = WS2812_BUF; i >= 0; i--) 00048 { 00049 ws.write(px.getBuf()); 00050 } 00051 } 00052 }
Generated on Thu Jul 14 2022 23:54:51 by
1.7.2