74,16 → 74,6 |
return ret; |
} |
|
// Function to read button status into a data structure |
void Pins_Read(BTN_STATUS *btns) { |
|
} |
|
// Function to write led values from the data structure |
void Leds_Write(LED_STATUS *leds) { |
|
} |
|
int main(void) { |
uint8_t buffer[32]; |
uint8_t result, length; |
118,29 → 108,119 |
Interrupt_Enable(); |
|
TLC59116_Init(); |
MCP23009_Init(); |
|
uint8_t leds[16] = {0x00, 0x00, 0x00, 0x00, |
0x00, 0x00, 0x00, 0x00, |
0x10, 0x10, 0x10, 0x10, |
0x10, 0x10, 0x10, 0x10}; |
TLC59116_Write_All(leds); |
BTN_STATUS btns; |
LED_VALUES leds = {0x00, 0x00, 0x00, 0x00, |
0x00, 0x00, 0x00, 0x00, |
0x00, 0x00, 0x00, 0x00, |
0x00, 0x00, 0x00, 0x00}; |
|
MCP23009_Init(); |
TLC59116_Write_All(&leds); |
|
// Check for received data over I2C |
Idle_Animation(); |
|
// Check for received data over I2C1 |
while (1) { |
uint8_t btn_value = MCP23009_Query(); |
MCP23009_Query(&btns); |
uint8_t i; |
for (i = 0; i < 8; i++) { |
if ((btn_value >> i) & 0x1) { |
leds[i] = 0x00; |
if ((btns.w >> i) & 0x1) { |
leds.w[i] = 0x00; |
} else { |
leds[i] = 0x10; |
leds.w[i] = 0x20; |
} |
} |
TLC59116_Write_All(leds); |
TLC59116_Write_All(&leds); |
} |
} |
|
void Idle_Animation(void) { |
LED_VALUES leds = {0}; |
uint8_t led_direction_bar[8] = {1,0,0,0,0,0,0,0}; |
uint8_t led_direction_dir[8] = {1,0,0,0}; |
uint8_t led_direction_ind[8] = {1,0,0,0}; |
uint8_t led_8_high_thres = 0x80; // Max brightness of the middle section |
uint8_t led_8_next_thresh = 0x40; // Threshold to start the next LED |
uint8_t led_4_high_thres = 0x80; // Max brightness of the side sections |
uint8_t led_4_next_thresh = 0x74; // Threshold to start the next LED |
uint8_t i, next_led; |
|
for (i = 0; i < 16; i++) leds.w[i] = 0x00; |
|
while (1) { |
|
// Update the LEDs in the middle section |
for (i = 0; i < 8; i++) { |
// Change the LED brightness depending on its direction |
if (led_direction_bar[i] == 1) { |
leds.w[i]++; |
} else if (led_direction_bar[i] == 2) { |
leds.w[i]--; |
} |
|
// Change direction if peak brightness is reached |
// When the brightness reaches a middle threshold, start |
// increasing the brightness of the next LED |
if (led_direction_bar[i] == 1 && leds.w[i] == led_8_high_thres) { |
led_direction_bar[i] = 2; |
} else if (led_direction_bar[i] == 1 && leds.w[i] == led_8_next_thresh) { |
next_led = (i == 7) ? 0 : i + 1; |
led_direction_bar[next_led] = 1; |
} else if (led_direction_bar[i] == 2 && leds.w[i] == 0x00) { |
led_direction_bar[i] = 0; |
} |
} |
|
// Update the LEDs in the right section |
for (i = 0; i < 4; i++) { |
// Change the LED brightness depending on its direction |
if (led_direction_dir[i] == 1) { |
leds.w[i+8]++; |
} else if (led_direction_dir[i] == 2) { |
leds.w[i+8]--; |
} |
|
// Change direction if peak brightness is reached |
// When the brightness reaches a middle threshold, start |
// increasing the brightness of the next LED |
if (led_direction_dir[i] == 1 && leds.w[i+8] == led_4_high_thres) { |
led_direction_dir[i] = 2; |
} else if (led_direction_dir[i] == 1 && leds.w[i+8] == led_4_next_thresh) { |
next_led = (i == 3) ? 0 : i + 1; |
led_direction_dir[next_led] = 1; |
} else if (led_direction_dir[i] == 2 && leds.w[i+8] == 0x00) { |
led_direction_dir[i] = 0; |
} |
} |
|
// Update the LEDs in the left section |
for (i = 0; i < 4; i++) { |
// Change the LED brightness depending on its direction |
if (led_direction_ind[i] == 1) { |
leds.w[i+12]++; |
} else if (led_direction_ind[i] == 2) { |
leds.w[i+12]--; |
} |
|
// Change direction if peak brightness is reached |
// When the brightness reaches a middle threshold, start |
// increasing the brightness of the next LED |
if (led_direction_ind[i] == 1 && leds.w[i+12] == led_4_high_thres) { |
led_direction_ind[i] = 2; |
} else if (led_direction_ind[i] == 1 && leds.w[i+12] == led_4_next_thresh) { |
next_led = (i == 3) ? 0 : i + 1; |
led_direction_ind[next_led] = 1; |
} else if (led_direction_ind[i] == 2 && leds.w[i+12] == 0x00) { |
led_direction_ind[i] = 0; |
} |
} |
|
// Write the LED values to the controller |
TLC59116_Write_All(&leds); |
|
// Delay a bit to slow down the animation |
__delay_ms(1); |
} |
} |
|
} |