Created
September 12, 2019 17:40
-
-
Save hughesjs/3717d1babb8ceb86a59b8d7450078ec8 to your computer and use it in GitHub Desktop.
Neopixel Send Byte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void send_byte(unsigned char byte){ | |
/* | |
Send a byte to the Neopixel matrix, timings extracted from Neopixel manual | |
value: unsigned char -> one byte value, will be sent as bits from Neopixel pin | |
*/ | |
for(unsigned char i = 0; i < 8; i++){ | |
if(byte & 1<<i){ | |
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET); | |
for (volatile unsigned char i = 0; i < 4; i++); //~700ns | |
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET); | |
for (volatile unsigned char i = 0; i < 3; i++); //~600ns | |
} else { | |
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET); | |
for (volatile unsigned char i = 0; i < 1; i++); //~350ns | |
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET); | |
for (volatile unsigned char i = 0; i < 4; i++); //~800ns | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment