// ----------------------------------------------------------------------- // ----------------------------------------------------------------------- void main(void) { initMSP430(); // Setup MSP to process IR and buttons int32 bitstring=0x00000000; int32 i; int8 packetIndex2=0; stopRobot(); _enable_interrupt(); while(1) { if (new_packet) { _disable_interrupt(); packetIndex2=0; //this part consolidates the incoming packet while (packetData[packetIndex2]!=2) { packetIndex2++; } packetIndex2++; while (packetIndex2<33) { bitstring+=packetData[packetIndex2]; bitstring<<=1; packetIndex2++; } if (bitstring==BUTTON_FIVE) //this part translates the packet { stopRobot(); } else if (bitstring==BUTTON_TWO) { moveRobotForward(); } else if (bitstring==BUTTON_FOUR) { moveRobotLeft(); } else if (bitstring==BUTTON_SIX) { moveRobotRight(); } else if (bitstring==BUTTON_EIGHT) { moveRobotBackwards(); } else if (bitstring==BUTTON_ONE) { moveRobotLeftSlow(); } else if (bitstring==BUTTON_THREE) { moveRobotRightSlow(); } else { stopRobot(); } for (i=0;i<0xFFFFF;i++); bitstring=0x00000000; packetIndex=0; _enable_interrupt(); new_packet=0; } else { bitstring=0x00000000; } } // end infinite loop } // end main
/* * main.c */ void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //Delays dictate how long each function is executed. To move forward or backward a further distance, //increase the delay after the moveRobotForward or moveRobotBackward functions. To turn larger angles, //increase the delay after the turnRobotRight or turnRobotLeft functions. initRobot(); __delay_cycles(3000000); //Delay here to give user time to get robot to floor moveRobotForward(); __delay_cycles(1000000); stopRobot(); __delay_cycles(1000000); moveRobotBackward(); __delay_cycles(1000000); stopRobot(); __delay_cycles(1000000); turnRobotRight(); __delay_cycles(300000); stopRobot(); __delay_cycles(1000000); turnRobotLeft(); __delay_cycles(300000); stopRobot(); __delay_cycles(1000000); turnRobotRight(); __delay_cycles(900000); stopRobot(); __delay_cycles(1000000); turnRobotLeft(); __delay_cycles(900000); stopRobot(); while(1) { } }
/* * main.c */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initRobot(); while (1) { moveRobotForward(100); __delay_cycles(700000); moveRobotBackward(100); __delay_cycles(700000); turnRobotLeft(100); __delay_cycles(700000); turnRobotRight(100); __delay_cycles(700000); turnRobotLeft(100); __delay_cycles(1500000); turnRobotRight(100); __delay_cycles(1500000); } }