Exemplo n.º 1
0
void commandTriggerSingleUltrasonicMeasurement(BaseSequentialStream *chp, int argc, char *argv[]) {
    (void)argc;
    (void)argv;

    readUltrasonic();
    chprintf(chp, "Ultrasonic distance %d, %d, %d.\r\n", dUS0, dUS1, dUS2);
}
Exemplo n.º 2
0
static msg_t Thread_Ultrasonic(void *arg) {
    (void)arg;
    chRegSetThreadName("Ultrasonic");

    waitForCompletingInitialization();

    while (TRUE) {
        if (!hasShell() || continuousMeasurements) {
            readUltrasonic();
        }
        else {
            chThdSleepMilliseconds(70);
        }
    }

    return (msg_t)0;
}
Exemplo n.º 3
0
// Main routine
void main(void) {
    OSCCON = 0x7C;          // Internal Oscillator 16MHz Enabled
    OSCTUNE = 0x5F;	    
    OSCCON2bits.PLLRDY = 1;
    VREFCON1 = 0xE0;		
    T2CON = 0x7B;		
    INTCONbits.GIE = 1;     // Global, peripheral & timer 2 interrupt enable 
    INTCONbits.PEIE = 1;
    PIE1bits.TMR2IE = 1;
    PR2 = 0xff;				// period registor 2 with max value
    VREFCON2 = 0;			// zero brightness
    LED_DIR = 0;			// LED pin on output 
    LED = 1;
    lcdinit();				// Initialize LCD in 4bit mode, ultrasonic and brightness
    lcdcmd(0x01);
    initUltrasonic();
    initBrightness();
    LED = 0;
    while(1)
    {
        readPIR();
        if(resPIR)
        {
            pirIndicate();
            readUltrasonic();
            f1 = 0;
            f2 = 1;
            while(resUS < 100 && resUS > 10)
            {
                T2CONbits.TMR2ON = 1;
                setBrightness();
                if(f2)
                {
                    lcdcmd(0x80);
                    sprintf(line1,"    Welcome !   ");
                    lcdstring(line1);
                    sprintf(line2,"   Chaitanya.   ");
                    lcdcmd(0xc0);
                    lcdstring(line2);
                    msDelay(1000);
                    f2 = 0;
                }
                if(sec >= 60)
                {
                    mn++;
                    sec = 0;
                }
                if(mn >= 60)
                {
                    hr++;
                    mn = 0;
                }
                sprintf(line1,"   Study Time   ");
                sprintf(line2,"    %i:%i:%i    ",hr,mn,sec);
                lcdcmd(0x80);
                lcdstring(line1);
                lcdcmd(0xc0);
                lcdstring(line2);
                eventL();
                eventL();
                readUltrasonic();
                f1 = 1;
            }
            T2CONbits.TMR2ON = 0;
            if(f1)
            {
                sprintf(line1,"   Thank You !  ");
                sprintf(line2,"   Good Bye...! ");
                lcdcmd(0x80);
                lcdstring(line1);
                lcdcmd(0xc0);
                lcdstring(line2);
                msDelay(3000);
                VREFCON2 = 0;
            }
            lcdcmd(0x01);
        }
    }
}