Пример #1
0
/**
 ** Main program
 */
int main(void) {
    
  //  initIO();
    
    // Initialize the LCD
    ssd1289 lcd;
    lcdInitialize(&lcd);
    
    uint8_t red = 255;;
    uint8_t green = 255;
    uint8_t blue = 255;
    
    while (1) {
        
        red = red == 255 ? 0 : 255;
        green = green == 255 ? 0 : 255;
        blue = blue == 255 ? 0 : 255;
        
        red = random();
        green = random();
        blue = random();
        
        for (uint16_t x = 0; x < 240; x++) {
            for (uint16_t y = 0; y < 320; y++) {
                lcd.setPixel(x, y, red, green, blue);
            }
        }
        

        
    }
    return 0; // never reached
}
Пример #2
0
int main(void)
{
  // VARIABLES
  int16_t dsValue; // value actualy get from sensor

  char lcdText[2][17];
  int32_t actualTemp;
  int32_t lastTemp; // value after filtering, without dividing, for trend derminination
  int16_t sampleCounter; // counts samples, for tren derminination
  uint8_t trend;

  // INITIALIZATIONS

  usartInitialization(9600);
  log("Usart initialized\n");

  lcdInitialize();
  log("Lcd initialized\n");

  lcdDisplayOn();
  log("Lcd display on\n");

  dsInitialize(&PORTB,1<<PB2);
  log("Ds initialized\n");

  dsSetResolution(NULL,bit12);
  log("Ds resolution is set\n");

  dsInitializeMovingAverageFilter();
  log("dsInitializeMovingAverageFilter\n");

  sampleCounter = 0;
  trend = DS_TREND_UNDEFINED;


  while(1)
    {
      // start conversion
      if(FALSE==dsStartConversion(NULL))
        {
          errorLcdlog;
        }

      // wait until sample ready
      if( dsWaitForConversionEnd() == FALSE)
        {
          errorLcdlog;
        }

      // read temperature
      if(dsReadTemperature(NULL,&dsValue)==FALSE)
        {
          errorLcdlog;
        }

      // filter value
      actualTemp = dsInsertSample(dsValue);

      // increase sample counter for trend determining
      sampleCounter++;

      if(sampleCounter==DS_TREND_PERIOD)
        {
          sampleCounter = 0;

          // determine trend
          if(lastTemp == -200)
            {
              lastTemp = actualTemp;
            }
          else if(lastTemp<actualTemp)
            {
              trend = DS_TREND_RISING;
            }
          else if(lastTemp>actualTemp)
            {
              trend = DS_TREND_FALLING;
            }
          else
            {
              //trend = DS_TREND_STAGNATING;
            }

            lastTemp = actualTemp;
        }

      // write temperature to th firsth row, other places fill with gap
      //temperatureToString(lcdText[0],actualTemp);
      sprintf(lcdText[0],"Temp: %d",actualTemp/16/25);
      memset(lcdText[strlen(lcdText[0])],' ',16-strlen(lcdText[0]));
      lcdText[0][16] = 0;

      // fill second row with trend
      switch(trend)
        {
        case DS_TREND_FALLING:
          strcpy(lcdText[1],"Trend: falling  ");
          break;

        case DS_TREND_RISING:
          strcpy(lcdText[1],"Trend: rising   ");
          break;

        case DS_TREND_STAGNATING:
          strcpy(lcdText[1],"Trend: no change");
          break;

        case DS_TREND_UNDEFINED:
          strcpy(lcdText[1],"                ");
          break;

        default:
          errorLcdlog;
        }

      // write lcd
      lcdGotoXY(0,0);
      lcdWrite(lcdText[0]);
      lcdGotoXY(0,1);
      lcdWrite(lcdText[1]);

      log(lcdText[0]);
      log(lcdText[1]);

    }

  return 0;
}