Exemple #1
0
 //method to figure out what sound to play
// === Timer Thread =================================================
static PT_THREAD (protothread_timer(struct pt *pt))
{
    PT_BEGIN(pt);
    tft_setCursor(100, 0);
    tft_setTextColor(ILI9340_WHITE);  tft_setTextSize(1);
    tft_writeString("Elapsed time : \t Score");
    while(1) {
        PT_YIELD_TIME_msec(1000) ;
        sys_time_seconds++ ;
        tft_fillRect(100, 10, 150, 8, ILI9340_BLACK);// x,y,w,h,radius,color
        tft_setCursor(100, 10);
        tft_setTextColor(ILI9340_YELLOW); tft_setTextSize(1);
        sprintf(buffer,"%*d %*d", 7, sys_time_seconds, 12, score);
        tft_writeString(buffer);
        tft_fillRect(175, 18,   2, 7, ILI9340_CYAN);
        tft_fillRect(248, 18,   2, 7, ILI9340_CYAN);
        tft_fillRect(175, 18,  75, 2, ILI9340_CYAN);
        tft_fillRect(175, 233,  2, 7, ILI9340_CYAN);
        tft_fillRect(248, 233,  2, 7, ILI9340_CYAN);
        tft_fillRect(175, 238, 75, 2, ILI9340_CYAN);

        if(score >= 50 && sys_time_seconds <= 60)  {
            tft_setCursor(100, 90);
            tft_setTextColor(ILI9340_GREEN);  tft_setTextSize(3);
            tft_writeString("You Win!");
        }
        else if(score <= -50 || sys_time_seconds > 60) {
            tft_setCursor(100, 90);
            tft_setTextColor(ILI9340_RED);  tft_setTextSize(3);
            tft_writeString("You Lose!");
        }
    } 
  PT_END(pt);
} // timer thread
Exemple #2
0
//==============================================================================
// Fill a rounded rectangle
//==============================================================================
void ICACHE_FLASH_ATTR tft_fillRoundRect(unsigned int x, unsigned int y,
                       unsigned int w, unsigned int h, 
                       unsigned int r, unsigned long color) 
{
  // smarter version
  tft_fillRect(x+r, y, w-2*r, h, color);

  // draw four corners
  fillCircleHelper(x+w-r-1, y+r, r, 1, h-2*r-1, color);
  fillCircleHelper(x+r    , y+r, r, 2, h-2*r-1, color);
}
Exemple #3
0
// === ADC Thread =============================================
static PT_THREAD (protothread_adc(struct pt *pt))
{
    PT_BEGIN(pt);
    myPaddle = (paddle*) malloc(sizeof(paddle));	
    myPaddle->xc = 4;
    static int adc_10;
    while(1) {      
        PT_YIELD_TIME_msec(2); 
        // read the ADC from pin 24 (AN11)
        adc_10 = ReadADC10(0);   // read the result of channel 9 conversion from the idle buffer
        AcquireADC10(); // not needed if ADC_AUTO_SAMPLING_ON below      
        //READADC10 value is between 0-1020
        tft_fillRect(myPaddle->xc, myPaddle->yc, 2, PADDLE_LEN, ILI9340_BLACK);
        if(adc_10 < 3) adc_10 = 0;
        else if (adc_10 > 920) adc_10 = 920;
        myPaddle->vyc = (adc_10 >> 2) - myPaddle->yc;
        myPaddle->yc = (adc_10 >> 2);
        tft_fillRect(myPaddle->xc, myPaddle->yc, 2, PADDLE_LEN, ILI9340_WHITE);
    } // END WHILE(1)
  PT_END(pt);
} // ADC thread
static PT_THREAD(protothread_anim(struct pt *pt)) {
    // runs the LCD and updates around 5/second
    PT_BEGIN(pt);
    //write to screen
    tft_fillRect(0,0, 50, 50, ILI9340_BLACK);//write black over previous message
    tft_setCursor(0, 0);
    tft_setTextColor(ILI9340_WHITE);  
    tft_setTextSize(1);//smallest size 
    sprintf(buffer,"%s%d", "time since startup:\n", PT_GET_TIME()/1000 );
    tft_writeString(buffer);
    
    PT_YIELD_TIME_msec(30);
    PT_END(pt);
} // animation thread
Exemple #5
0
//===================== Capture ==================== //
// Discharges capacitor, displays  and begins measurement of C1INA
static PT_THREAD (protothread_capture(struct pt *pt))
{
    PT_BEGIN(pt);
    while(1) {
    // sets pin 7 to an output
    mPORTBSetPinsDigitalOut(BIT_3);
    mPORTBClearBits(BIT_3);
    tft_setCursor(10, 50);
    tft_setTextColor(ILI9340_YELLOW);  tft_setTextSize(3);
    tft_writeString("Capacitance: ");
    
    //sets up for the capacitor reading
    char buffer[20];
    tft_setCursor(10, 90);
    tft_fillRect(10,90, 300, 100, ILI9340_BLACK);
    sprintf(buffer,"%.1f nF",cap);
    tft_setTextColor(ILI9340_WHITE);
    
    //displays the capacitor value if it is above the threshold of 1 nF
    if(cap < 1.0*(1-ERROR))
        tft_writeString("No capacitor");
    else
        tft_writeString(buffer);
    

    cap = 0.0;
    PT_YIELD_TIME_msec(1);
    
    //Clear timer and sets pin 7 as input
    WriteTimer2(0);    
    mPORTBSetPinsDigitalIn(BIT_3);
    
    PT_YIELD_TIME_msec(100);
    }
    PT_END(pt);
} // capture
Exemple #6
0
//==============================================================================
void ICACHE_FLASH_ATTR tft_fillScreen(unsigned long color)
{
	tft_fillRect(0, 0, _width, _height, color);
}