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:

  • We make the first group of 256 values of the range of Pot1 color our Tx with shades of red.  (Blue and green components = 0.)
  • The second group of 256 values color it in shades of blue.  (Red & green components = 0.)
  • The third group of 256 values color it in shades of green. (Red & blue components = 0.)
  • The fourth group of 256 values color it in shades of gray: all color components have the same value.

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()

 
  

31 of 33
Copyright Notice and Author Information