reduced message bytes for BLE
Dependencies: BLE_API mbed nRF51822
Fork of Inp_Fiber_Logo_FOTA by
neopixel.cpp
00001 #include "mbed.h" // remove line if not using mbed 00002 00003 #include <stdbool.h> 00004 #include <stdint.h> 00005 #include <stdlib.h> 00006 #include "nrf_delay.h" 00007 #include "nrf_gpio.h" 00008 #include "neopixel.h" 00009 00010 00011 void neopixel_init(neopixel_strip_t *strip, uint8_t pin_num, uint16_t num_leds) 00012 { 00013 strip->leds = (color_t*) malloc(sizeof(color_t) * num_leds); 00014 strip->pin_num = pin_num; 00015 strip->num_leds = num_leds; 00016 nrf_gpio_cfg_output(pin_num); 00017 NRF_GPIO->OUTCLR = (1UL << pin_num); 00018 for (int i = 0; i < num_leds; i++) 00019 { 00020 strip->leds[i].simple.g = 0; 00021 strip->leds[i].simple.r = 0; 00022 strip->leds[i].simple.b = 0; 00023 } 00024 } 00025 00026 void neopixel_clear(neopixel_strip_t *strip) 00027 { 00028 for (int i = 0; i < strip->num_leds; i++) 00029 { 00030 strip->leds[i].simple.g = 0; 00031 strip->leds[i].simple.r = 0; 00032 strip->leds[i].simple.b = 0; 00033 } 00034 neopixel_show(strip); 00035 } 00036 00037 void neopixel_show(neopixel_strip_t *strip) 00038 { 00039 const uint8_t PIN = strip->pin_num; 00040 NRF_GPIO->OUTCLR = (1UL << PIN); 00041 //nrf_delay_us(50); 00042 nrf_delay_us(100); 00043 for (int i = 0; i < strip->num_leds; i++) 00044 { 00045 for (int j = 0; j < 3; j++) 00046 { 00047 if ((strip->leds[i].grb[j] & 128) > 0) {NEOPIXEL_SEND_ONE} 00048 else {NEOPIXEL_SEND_ZERO} 00049 00050 if ((strip->leds[i].grb[j] & 64) > 0) {NEOPIXEL_SEND_ONE} 00051 else {NEOPIXEL_SEND_ZERO} 00052 00053 if ((strip->leds[i].grb[j] & 32) > 0) {NEOPIXEL_SEND_ONE} 00054 else {NEOPIXEL_SEND_ZERO} 00055 00056 if ((strip->leds[i].grb[j] & 16) > 0) {NEOPIXEL_SEND_ONE} 00057 else {NEOPIXEL_SEND_ZERO} 00058 00059 if ((strip->leds[i].grb[j] & 8) > 0) {NEOPIXEL_SEND_ONE} 00060 else {NEOPIXEL_SEND_ZERO} 00061 00062 if ((strip->leds[i].grb[j] & 4) > 0) {NEOPIXEL_SEND_ONE} 00063 else {NEOPIXEL_SEND_ZERO} 00064 00065 if ((strip->leds[i].grb[j] & 2) > 0) {NEOPIXEL_SEND_ONE} 00066 else {NEOPIXEL_SEND_ZERO} 00067 00068 if ((strip->leds[i].grb[j] & 1) > 0) {NEOPIXEL_SEND_ONE} 00069 else {NEOPIXEL_SEND_ZERO} 00070 } 00071 } 00072 } 00073 00074 uint8_t neopixel_set_color(neopixel_strip_t *strip, uint16_t index, uint8_t red, uint8_t green, uint8_t blue ) 00075 { 00076 if (index < strip->num_leds) 00077 { 00078 strip->leds[index].simple.r = red; 00079 strip->leds[index].simple.g = green; 00080 strip->leds[index].simple.b = blue; 00081 } 00082 else 00083 return 1; 00084 return 0; 00085 } 00086 00087 uint8_t neopixel_set_color_and_show(neopixel_strip_t *strip, uint16_t index, uint8_t red, uint8_t green, uint8_t blue) 00088 { 00089 if (index < strip->num_leds) 00090 { 00091 strip->leds[index].simple.r = red; 00092 strip->leds[index].simple.g = green; 00093 strip->leds[index].simple.b = blue; 00094 neopixel_show(strip); 00095 } 00096 else 00097 return 1; 00098 return 0; 00099 } 00100 00101 void neopixel_destroy(neopixel_strip_t *strip) 00102 { 00103 free(strip->leds); 00104 strip->num_leds = 0; 00105 strip->pin_num = 0; 00106 }
Generated on Mon Aug 22 2022 18:58:14 by
1.7.2
