so i use atmel studio to program an avr128db48 microchip. the idea is that a led switches modes each time the switch is clicked. clicked once = off, switched the second time = on, switched the third time = off-on-off-on.......
I need to do this with enums and switch case and i thought that it went pretty well but it didnt work. so maybe somebody here knows whats wrong with the code.
#include <atmel_start.h>
#include <util/delay.h>
#define F_CPU 4000000 UL
int main(void)
{
typedef enum SWITCHSTATE
{
SWITCHED1,
SWITCHED2,
SWITCHED3
};
int a = 0;
int b = SWITCHED1;
while (1)
{
if (SWITCH_get_level(false))
{
a++;
if (a == 3)
{
a = 0;
}
}
if (a == 0)
{
b = SWITCHED1;
}
else if (a == 1)
{
b = SWITCHED2;
}
else if (a == 2)
{
b = SWITCHED3;
}
switch (b)
{
case INGEDRUKT1:
LED_set_level(true);
break;
case INGEDRUKT2:
LED_set_level(false);
break;
case INGEDRUKT3:
LED_set_level(false);
_delay_ms(250);
LED_set_level(true);
_delay_ms(250);
break;
}
}
}