summaryrefslogtreecommitdiff
path: root/ws2812/main.c
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2020-10-31 20:49:22 +0100
committerxengineering <mail2xengineering@protonmail.com>2020-10-31 20:49:22 +0100
commit0314c77fd9fd9372bdef8c190cef7e78dc2ae5b2 (patch)
tree86f8a9ab0287dcdd9c923a2b49e8b6a07d167fc9 /ws2812/main.c
parent45def2a4827b206fc3e2351a29719d16b980338b (diff)
downloadstm32f103c8-examples-0314c77fd9fd9372bdef8c190cef7e78dc2ae5b2.tar
stm32f103c8-examples-0314c77fd9fd9372bdef8c190cef7e78dc2ae5b2.tar.zst
stm32f103c8-examples-0314c77fd9fd9372bdef8c190cef7e78dc2ae5b2.zip
ws2812: No usage of Heap anymore
Diffstat (limited to 'ws2812/main.c')
-rw-r--r--ws2812/main.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/ws2812/main.c b/ws2812/main.c
index 926cd68..323d03c 100644
--- a/ws2812/main.c
+++ b/ws2812/main.c
@@ -6,8 +6,9 @@
#include "ws2812.h"
-#define DELAY 30000 // 18,000,000 nops are one second
-#define BRIGHTNESS 100
+#define DELAY 90000 // 18,000,000 nops are one second @ 72 MHz (one nop --> 4 clock cycles)
+#define BRIGHTNESS 30
+#define LED_ARRAY_LENGTH 3
void clock_init(void);
@@ -15,31 +16,32 @@ void gpio_init(void);
void delay(void);
-ws2812_init_typedef ws2812;
-
-
int main(void)
{
clock_init();
gpio_init();
- ws2812_init(&ws2812, GPIOB, GPIO13, 1, 1);
-
- while(1){
- /*ws2812_send_led(&ws2812, BRIGHTNESS, 0, 0);
- delay();
- ws2812_send_led(&ws2812, 0, BRIGHTNESS, 0);
- delay();
- ws2812_send_led(&ws2812, 0, 0, BRIGHTNESS);
- delay();
- ws2812_send_led(&ws2812, BRIGHTNESS, BRIGHTNESS, BRIGHTNESS);
- delay();*/
-
- for (uint16_t i=0; i<=255; i++){
- ws2812_send_led(&ws2812, i, 0, 0);
+ uint8_t led_array_buffer[LED_ARRAY_LENGTH*WS2812_NUMBER_OF_COLORS];
+ WS2812_ARRAY led_panel;
+ ws2812_init(&led_panel, GPIOB, GPIO13, (uint8_t *)led_array_buffer, LED_ARRAY_LENGTH);
+
+ while(1)
+ {
+ for (uint16_t i=0; i<=BRIGHTNESS; i++)
+ {
+ ws2812_set_array_led(&led_panel, 0, i, 0, 0);
+ ws2812_set_array_led(&led_panel, 1, 0, i, 0);
+ ws2812_set_array_led(&led_panel, 2, 0, 0, i);
+
+ ws2812_write_leds(&led_panel);
delay();
}
- for (uint16_t i=255; i>0; i--){
- ws2812_send_led(&ws2812, i, 0, 0);
+ for (uint16_t i=BRIGHTNESS; i>0; i--)
+ {
+ ws2812_set_array_led(&led_panel, 0, i, 0, 0);
+ ws2812_set_array_led(&led_panel, 1, 0, i, 0);
+ ws2812_set_array_led(&led_panel, 2, 0, 0, i);
+
+ ws2812_write_leds(&led_panel);
delay();
}
}