Tool/software:
I am using TMS320F280049C microcontroller and i want to use the Ws2812B neo pixel led's to light up in my desired colour and in my code the it turns on all the number of mentioned led's white and not my desired colour. I will attach my code. Please help me resolve this issue as soon as possible. Thank You.
#include "device.h" #include "gpio.h" #define NEOPIXEL_PIN 4 #define NUM_LEDS 2 // Number of LEDs #define BLINK_DELAY 500000 // 500ms delay // GRB color values (0-255) #define RED 0, 255, 0 // Green component for red color #define GREEN 255, 0, 0 // Red component for green color #define BLUE 0, 0, 255 // Blue component // System clock frequency in MHz for cycle calculations #define SYS_FREQ_MHZ (DEVICE_SYSCLK_FREQ / 1000000) // Timing parameters (in microseconds) #define T0H 0.4f // High time for '0' bit #define T1H 0.8f // High time for '1' bit #define T0L 0.85f // Low time for '0' bit #define T1L 0.45f // Low time for '1' bit // Convert timing to CPU cycles #define CYCLES_PER_US SYS_FREQ_MHZ #define T0H_CYCLES (uint32_t)(T0H * CYCLES_PER_US) #define T1H_CYCLES (uint32_t)(T1H * CYCLES_PER_US) #define T0L_CYCLES (uint32_t)(T0L * CYCLES_PER_US) #define T1L_CYCLES (uint32_t)(T1L * CYCLES_PER_US) void delay_cycles(uint32_t cycles) { while (cycles--) { __asm(" NOP"); } } void send_neopixel_byte(uint8_t byte, uint16_t pin) { for (int i = 7; i >= 0; i--) { uint8_t bit_val = (byte >> i) & 1; GPIO_writePin(pin, 1); // Signal start of bit if (bit_val) { delay_cycles(T1H_CYCLES - 2); // High pulse for '1' GPIO_writePin(pin, 0); delay_cycles(T1L_CYCLES - 2); // Low period for '1' } else { delay_cycles(T0H_CYCLES - 2); // High pulse for '0' GPIO_writePin(pin, 0); delay_cycles(T0L_CYCLES - 2); // Low period for '0' } } } void set_all_leds(uint8_t green, uint8_t red, uint8_t blue) { for (int j = 0; j < NUM_LEDS; j++) { send_neopixel_byte(green, NEOPIXEL_PIN); // GRB order send_neopixel_byte(red, NEOPIXEL_PIN); send_neopixel_byte(blue, NEOPIXEL_PIN); } GPIO_writePin(NEOPIXEL_PIN, 0); // Reset signal delay_us(60); // Hold low for 60µs } void main(void) { Device_init(); Device_initGPIO(); GPIO_setDirectionMode(NEOPIXEL_PIN, GPIO_DIR_MODE_OUT); while (1) { set_all_leds(GREEN); // Green component for red color delay_us(BLINK_DELAY); set_all_leds(0, 0, 0); // Turn off LEDs delay_us(BLINK_DELAY); } }