예제 #1
0
파일: motor.c 프로젝트: eeshanl/ee472
//vTaskContolMotor is a Task that controls the movements of the motor
//the motor can move right, left, forward, backward, upRight, upLeft,
//downRight and downLeft
//PD7 ==> AOUT
//PD3 ==> AIN
//PD4 ==> BOUT
//PD2 ==> BIN
//PD6 ==> STDBY
void vTaskControlMotor(void *vParameters) {
  //the following commands for the controlling the tank through
  // the blue tooth app "blueTerm"
  //'w' pressed to go forward
  //'s' pressed to go back
  //'a' pressed to go left
  //'d' pressed to go right
  //'q' pressed to go upLeft
  //'e' pressed to go upRight
  //'z' pressed to go back left
  //'x' pressed to go back right
  //if any other character is pressed, the tank stops
  while(1) {
    //gets the currentKey pressed by the user
    currentKey = keymaster();
    if (state == 6) { // (!auton) {
      //if the up key is pressed, tank should move forward
      if (currentKey == 1 || bluetoothSignal == 'w') { 
        goForward();
      } else if (currentKey == 2 || bluetoothSignal == 's') {//if down is pressed
        goBackWard();
      } else if (currentKey == 3 || bluetoothSignal == 'a') { //if left is pressed
        goLeft();
      } else if (currentKey == 4 || bluetoothSignal == 'd') { //if right is pressed
        goRight();
      } else if(currentKey == 6 || bluetoothSignal == 'q'){ // if the upLeft key is pressed
        goUpLeft();
      } else if(currentKey == 7 || bluetoothSignal == 'e'){ // if the upRight key is pressed
        goUpRight();
      } else if(currentKey == 8 || bluetoothSignal == 'z'){ //if the backleft key is pressed
        goBackLeft();
      } else if(currentKey == 9 || bluetoothSignal == 'x'){//if the backRight key is pressed
        goBackRight();
      } else {
        stopTank();
      }
    }
    if (bluetoothSignal == 'r') {
      state = 2;
    }
    //delays time between task
    vTaskDelay(20);
  }
}
예제 #2
0
파일: main.c 프로젝트: mgolub2/EE472_lab3
// Main loop of the program
int main(void)
{
    //
    // Set the clocking to run directly from the crystal. 8Mhz
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
    delay(500);
    LED_init();
    delay(500);
    ADC_init(); //init the adc
    delay(500);
    timer0_init(); //init the first timer
    delay(500);
    timer1_init(); //second timer
    delay(500);
    key_init(); //keypad
    display_init();
    CPUcpsie(); //turn on cpu inttrupts

    //init all prices and indexes
    int upDownIndex = 0; 
    int currDollars = 0;
    int currCents = 0;
    int leftRightIndex = 0;
    display_on(1,1); 
    print_welcome(); //print initial welcome menu
 
     /*
    handles key inputs
    User can toggle through display menus (welcome menu, food menu,...) 
    using LEFT and RIGHT
    While on the food menu, user can toggle through food options using UP 
    and DOWN and select food items using SELECT.
    */
    while(1)
    {
      int currentKey = keymaster();
      if (!readKey) { //if we have not read the key since it has been updated
        switch (currentKey) //main control flow loop
        {
          case UP:
            if (upDownIndex) {
              upDownIndex--; //de-inc the vertical index
              print_menu(upDownIndex, currDollars, currCents);
            }
            break;
          case DOWN:
            if (upDownIndex < maxUpDownIndex) {
              upDownIndex++; //inc the vertical index
              print_menu(upDownIndex, currDollars, currCents);
            }
            break;
          case RIGHT:
            if (leftRightIndex < maxLeftRightIndex) {
              leftRightIndex++; //inc the left right index
              select_menu(&leftRightIndex, upDownIndex, currDollars, currCents);
            }
            break;
          case LEFT:
            if (leftRightIndex) {
              leftRightIndex--; //de-inc the left right index
              select_menu(&leftRightIndex, upDownIndex, currDollars, currCents);
            }
            break;
          case SELECT:
            currDollars += dollars[upDownIndex]; //update the total costs
            currCents += cents[upDownIndex];
            if (currCents >= 100) {
              currDollars += 1;
              currCents -= 100;
            }
            print_menu(upDownIndex, currDollars, currCents);
            break;
        }
      }
      readKey = 1; //tell timer 0 we have read the key
      //Reset the totals for the costs
      if (leftRightIndex == 0) {
        currDollars = 0;
        currCents = 0;
      }
    }

}