Example #1
0
/*
 * main.c
 */
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

    initializeADC10();
	
    initializeLedPins();

    for(;;){

    	checkLeftSensor();

    	if (ADC10MEM < 0x2FF)
    		P1OUT &= ~BIT0;
    	else
    		P1OUT |= BIT0;

    	_delay_cycles(100);

    	checkRightSensor();

    	if (ADC10MEM < 0x23F)
    		P1OUT &= ~BIT6;
    	else
    		P1OUT |= BIT6;

    }

}
/*
 * main.c
 */
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

   initializeADC10();
   P1DIR |= BIT0;
   P1DIR |= BIT6;

for (;;){
	leftSensorVoltage=getLeftSensorVoltage();

	if(leftSensorVoltage < 0x230){
		P1OUT &= ~BIT0;
	}
	else{
		P1OUT |= BIT0;
	}

	rightSensorVoltage=getRightSensorVoltage();

	if(rightSensorVoltage<0x230){
		P1OUT &= ~BIT6;
	}
	else{
		P1OUT |= BIT6;
	}
}

return 0;

}
Example #3
0
/*
 * main.c
 */
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;        // Stop watchdog timer

   initializeMotor();

   initializeADC10();
   P1DIR |= BIT0;
   P1DIR |= BIT6;

for (;;){
        leftSensorVoltage=getLeftSensorVoltage();

        if(leftSensorVoltage < LEFTDISTANCE){
                P1OUT &= ~BIT0;
                moveRobot(SMALLRIGHT);
        }
        else{
                P1OUT |= BIT0;
                moveRobot(FORWARD);
        }

        rightSensorVoltage=getRightSensorVoltage();

        if(rightSensorVoltage<RIGHTDISTANCE){
                P1OUT &= ~BIT6;
                moveRobot(SMALLLEFT);
        }
        else{
                P1OUT |= BIT6;
                moveRobot(FORWARD);
        }
}

return 0;

}