Added off state. Fixed state machine and adjusted based on PCB
This commit is contained in:
parent
10a97b20ee
commit
8aace49723
@ -9,7 +9,7 @@
|
||||
// Port A0 - A3 -> LED Data
|
||||
// Port A5 -> Select Output
|
||||
// Port A4, A6 -> I2C Display
|
||||
// Port A7 -> Button Input (Pulled-Up)
|
||||
// Port A7 -> Enable Output
|
||||
// Port B2 -> Button Input (Pulled-Up)
|
||||
|
||||
// Size of each strip
|
||||
@ -123,10 +123,11 @@ void sun_and_moon(uint8_t count, uint8_t* idx, uint8_t colour, uint8_t led);
|
||||
void clock_bg(uint8_t count, uint8_t* idx, uint8_t colour, uint8_t led);
|
||||
void clock_no_bg(uint8_t count, uint8_t* idx, uint8_t colour, uint8_t led);
|
||||
void loading(uint8_t count, uint8_t* idx, uint8_t colour, uint8_t led);
|
||||
void off(uint8_t count, uint8_t* idx, uint8_t colour, uint8_t led);
|
||||
|
||||
void (*func_list[4])(uint8_t, uint8_t*, uint8_t, uint8_t) =
|
||||
void (*func_list[5])(uint8_t, uint8_t*, uint8_t, uint8_t) =
|
||||
{
|
||||
sun_and_moon, clock_bg, clock_no_bg, loading
|
||||
sun_and_moon, clock_bg, clock_no_bg, loading, off
|
||||
};
|
||||
|
||||
void (*send_ptr[4])(uint8_t) =
|
||||
@ -134,15 +135,26 @@ void (*send_ptr[4])(uint8_t) =
|
||||
send_bit_led0, send_bit_led1, send_bit_led2, send_bit_led3
|
||||
};
|
||||
|
||||
enum states
|
||||
{
|
||||
STATE_SUN_MOON = 0,
|
||||
STATE_CLOCK_BG1,
|
||||
STATE_CLOCK_BG2,
|
||||
STATE_CLOCK_NO1,
|
||||
STATE_CLOCK_NO2,
|
||||
STATE_LOADING,
|
||||
STATE_PC,
|
||||
STATE_OFF
|
||||
};
|
||||
|
||||
uint8_t led0_idx = 0;
|
||||
uint8_t led1_idx = 0;
|
||||
uint8_t led2_idx = 0;
|
||||
uint8_t led3_idx = 0;
|
||||
uint8_t colour = 0;
|
||||
uint8_t func_idx = 0;
|
||||
uint8_t btn1_old_state = 1;
|
||||
uint8_t btn2_old_state = 1;
|
||||
uint8_t colour_state = 0;
|
||||
uint8_t btn_old_state = 1;
|
||||
uint8_t colour_state = STATE_SUN_MOON;
|
||||
uint8_t current_state;
|
||||
|
||||
int main()
|
||||
@ -185,42 +197,58 @@ while(1)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Button 1 Press
|
||||
current_state = PINA & 0x80;
|
||||
if (btn1_old_state && !current_state)
|
||||
{
|
||||
led0_idx = 0;
|
||||
led1_idx = 0;
|
||||
led2_idx = 0;
|
||||
led3_idx = 0;
|
||||
|
||||
func_idx++;
|
||||
func_idx %= sizeof(func_list) / sizeof(func_list[0]);
|
||||
}
|
||||
btn1_old_state = current_state;
|
||||
|
||||
// Button 2 Press
|
||||
// Button Press
|
||||
current_state = PINB & 0x04;
|
||||
if (btn2_old_state && !current_state)
|
||||
if (btn_old_state && !current_state)
|
||||
{
|
||||
switch (colour_state)
|
||||
{
|
||||
case 0:
|
||||
colour = 1;
|
||||
colour_state = 1;
|
||||
break;
|
||||
case 1:
|
||||
case STATE_SUN_MOON:
|
||||
func_idx = 1;
|
||||
colour_state = STATE_CLOCK_BG1;
|
||||
colour = 0;
|
||||
colour_state = 2;
|
||||
PORTA ^= 0x20;
|
||||
break;
|
||||
case 2:
|
||||
colour_state = 0;
|
||||
|
||||
case STATE_CLOCK_BG1:
|
||||
colour_state = STATE_CLOCK_BG2;
|
||||
colour = 1;
|
||||
break;
|
||||
|
||||
case STATE_CLOCK_BG2:
|
||||
func_idx = 2;
|
||||
colour_state = STATE_CLOCK_NO1;
|
||||
colour = 0;
|
||||
break;
|
||||
|
||||
case STATE_CLOCK_NO1:
|
||||
colour_state = STATE_CLOCK_NO2;
|
||||
colour = 1;
|
||||
break;
|
||||
|
||||
case STATE_CLOCK_NO2:
|
||||
func_idx = 3;
|
||||
colour_state = STATE_LOADING;
|
||||
colour = 0;
|
||||
break;
|
||||
|
||||
case STATE_LOADING:
|
||||
func_idx = 4;
|
||||
PORTA ^= 0x20;
|
||||
colour_state = STATE_PC;
|
||||
break;
|
||||
|
||||
case STATE_PC:
|
||||
PORTA ^= 0x20;
|
||||
colour_state = STATE_OFF;
|
||||
break;
|
||||
|
||||
case STATE_OFF:
|
||||
func_idx = 0;
|
||||
colour_state = STATE_SUN_MOON;
|
||||
break;
|
||||
}
|
||||
}
|
||||
btn2_old_state = current_state;
|
||||
btn_old_state = current_state;
|
||||
}
|
||||
}
|
||||
|
||||
@ -427,8 +455,7 @@ void show_leds()
|
||||
|
||||
void init()
|
||||
{
|
||||
DDRA = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 5);
|
||||
PORTA = (1 << 7);
|
||||
DDRA = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 7);
|
||||
PORTB = (1 << 2);
|
||||
|
||||
#ifdef ENABLE_OLED
|
||||
@ -632,6 +659,21 @@ void loading(uint8_t count, uint8_t* idx, uint8_t colour, uint8_t led)
|
||||
*idx %= count * 2;
|
||||
}
|
||||
|
||||
void off(uint8_t count, uint8_t* idx, uint8_t colour, uint8_t led)
|
||||
{
|
||||
uint8_t black[3] =
|
||||
{
|
||||
pgm_read_byte(&gamma8[0x00]),
|
||||
pgm_read_byte(&gamma8[0x00]),
|
||||
pgm_read_byte(&gamma8[0x00])
|
||||
};
|
||||
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
send_pixel(black[0], black[1], black[2], led);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_OLED
|
||||
void init_display()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user