// experi6f.c

void waitalittlewhile(void);  // timer for test only

#include <malloc.h>
#include <conio.h>
#include <stdio.h>
#include <bios.h>

// include header with constants
#include "constant.h"

// include header with external prototypes
#include "extern6f.h"

enum
{
  WarningLED,
  MainMotor,
  LeftArmMotor
};

void main(void)
{
  int x,y,*ptr1,*ptr2;

  get_port(); // get the port number and establish register locations

  // make everthing an output
  set_up_ppi(Aout_CUout_Bout_CLout);

  if(!ConfigureOutput(WarningLED,PA0))
      printf("Error setting up Warning LED = %d port select = %d\n"
	,WarningLED,PA0);

  if(!ConfigureOutput(MainMotor,PA1))
      printf("Error setting up Main Motor = %d port select = %d\n"
	,MainMotor,PA1);

  if(!ConfigureOutput(LeftArmMotor,PA2))
      printf("Error setting up Left Arm Motor = %d port select = %d\n"
	,LeftArmMotor,PA2);

  while(!kbhit())
  {
    if(!TurnOn(WarningLED))
      printf("Can't turn on the Warning LED\n");
    else printf("Turned on the Warning LED\n");
    waitalittlewhile();

    if(!TurnOff(WarningLED))
      printf("Can't turn off the Warning LED\n");
    else printf("Turned off the Warning LED\n");
    waitalittlewhile();

    if(!TurnOn(LeftArmMotor))
      printf("Can't turn on the Left Arm Motor\n");
    else printf("Turned on the Left Arm Motor\n");
    waitalittlewhile();

    if(!TurnOff(LeftArmMotor))
      printf("Can't turn off the Left Arm Motor\n");
    else printf("Turned off the Left Arm Motor\n");
    waitalittlewhile();

    if(!TurnOn(MainMotor))
      printf("Can't turn on the Main Motor\n");
    else printf("Turned on the Main Motor\n");
    waitalittlewhile();

    if(!TurnOff(MainMotor))
      printf("Can't turn off the Main Motor\n");
    else printf("Turned off the Main Motor\n");
    waitalittlewhile();
  }

  // don't forget to free memory!
  FreeOutputControl();

  portaoff();

}

void waitalittlewhile(void)
{
  long x;

  for(x=0L; x<100000L; x++);

} // end waitalittlewhile()

// end experi6f.c
