Monday, May 19, 2008

TouchShield: SoftLED

Inspired by Matt's bitDJ program, this TouchShield example puts a modern spin on those retro LED matrices. Sure, OLED screens are LED matrices too with one difference, they're the cool kind ;-)



If you look at the code, you'll notice this app builds off the previous pointInRect tutorial post.

TouchShield code,

COLOR BLACK = {0,0,0};
COLOR RED = {255,0,0};
COLOR BLUE = {0,0,255};
COLOR WHITE = { 255,255,255};

unsigned char x,y,state;
POINT p;

void setup()
{
state = ON;
ledControl(state);
drawButton(state);
}

LCD_RECT buttonRect = {10,100,40,120};

void loop()
{

if (touch_get_cursor(&p))
{
if (pointInRect(p,buttonRect))
{

if (state==ON)
{

state = OFF;
ledControl(state);
drawButton(state);

}
else
{
state = ON;
ledControl(state);
drawButton(state);
}

}



}

}

void drawButton(unsigned char state)
{

lcd_rect(buttonRect, BLUE, BLACK);

if (state == ON)
{
lcd_puts("On", 20, 108,BLUE,BLACK);
}
else
{
lcd_puts("Off", 20, 108,BLUE,BLACK);
}

}


void ledControl(unsigned char state)
{
COLOR ledColor = {0,0,0};

if (state == ON)
{
ledColor.red = 255;
}

for(x=1;x<4;x++) y="1;y<4;y++)">

No comments: