TCPmaker : Visual Tour Sending Messages to Screen Controls |
The HandlePot1() function is shown below. In this function, we use the new value that has just been assigned to the Pot1 variable in sendPotValue(), and calculate a new set of color components (red, green, and blue) for the Tx control whose id is tx12.
Our PIC processor's ADC is initialized to 10-bit resolution (i.e. 0-1023), yet each of the color components has an 8-bit value (0-255). To make the color change in a way that looks understandable:
The number of the color group is local variable ColorPrimary: the top 2 bits of the Pot1 value. The 8-bit shade value is local variable ColorMod.
Here is the code for function HandlePot1():
void HandlePot1(void)
{
unsigned char ColorMod;
unsigned char ColorPrimary;
// Handle rotation of the pot on the PICDEM.net 2 demo board
switch (PageNum)
{
case 0 : // index page : modify text size, color, rotation
// Change color of text
ColorPrimary = Pot1 >> 8;
ColorMod = Pot1 % 256;
switch (ColorPrimary)
{
case 0 : // Red
mtSetTextColor((rom char *)"tx12", ColorMod, 0, 0);
break;
case 1 : // Green
mtSetTextColor((rom char *)"tx12", 0, ColorMod, 0);
break;
case 2 : // Blue
mtSetTextColor((rom char *)"tx12", 0, 0, ColorMod);
break;
case 3 : // Greys
mtSetTextColor((rom char *)"tx12", ColorMod, ColorMod, ColorMod);
break;
}
break;
case 1 : // pg1 : modify buttons & LEDs
// Nothing to do...
break;
case 2 : // pg2 : modify any control
// Nothing to do...
break;
case 3 : // pg3 : modify variables & associations
// Nothing to do...
break;
case 4 : // pg4 : modify controls to show context
// Nothing to do...
break;
}
} // HandlePot1()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |