Skip to content

Instantly share code, notes, and snippets.

@hughesjs
Created September 12, 2019 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hughesjs/3717d1babb8ceb86a59b8d7450078ec8 to your computer and use it in GitHub Desktop.
Save hughesjs/3717d1babb8ceb86a59b8d7450078ec8 to your computer and use it in GitHub Desktop.
Neopixel Send Byte
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