Skip to content

Instantly share code, notes, and snippets.

@amokan
Created August 17, 2014 23:20
Show Gist options
  • Save amokan/288795f6e5d0eb1306e4 to your computer and use it in GitHub Desktop.
Save amokan/288795f6e5d0eb1306e4 to your computer and use it in GitHub Desktop.
setLED function

Calling setLED from the existing readADC() function where selector changes are detected. Clearly my port settings are wayyyy off.

if ( ( s | selector ) & 0x20 )
{
    int lastSelector = selector;
    selector = s >> 6;
    selector = selector < 15 ? selector : 15;
    if ( selector != lastSelector )
    {
        // new algorithm chosen - exit
        setLED(selector);
        ret = 1;
    }
}
void setLED(int current)
{
PORTA = 0;
PORTB = 0;
int apins = BIT_2 | BIT_3;
int bpins = BIT_4 | BIT_6 | BIT_7 | BIT_10 | BIT_11 | BIT_12 | BIT_15;
PORTACLR = apins;
PORTBCLR = bpins;
switch ( current )
{
case 0:
PORTASET = BIT_3;
PORTBSET = BIT_4;
break;
case 1:
PORTASET = BIT_3;
PORTBSET = BIT_6;
break;
case 2:
PORTASET = BIT_3;
PORTBSET = BIT_11;
break;
case 3:
PORTASET = BIT_2 & BIT_3;
PORTBSET = BIT_12;
break;
default:
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment