/*

	minor demo for Handy Board w/ Expansion Board
	
	This program...
	- displays analog inputs 6 to 2 of handyboard
	- couples analog potentiometer input to servo 0
	- couples analog potentiometer input to motor 0

	version 1.0 -- 9/27/2004
	Ericson Mar
	
*/

void main()
{
    int i;

    printf("Press START to  test servo...\n");
    start_press();  /* halt until user presses START */

    /* enables expansion board servo control signals */
    init_expbd_servos(1);

    while (1) {
	/* display the pot value */
        printf("Knob: %d ", knob());

	/* display analog 6 to 2 values */
        for (i= 6; i >=2; i--) {
          printf("%d ", analog(i));
	  }

	/* print end-of-line so next printf starts from scratch */
        printf("\n");

	/* couple servo 0 angular position (0 - 3000) with pot */
	servo0 = (int)((float)knob() / 255.0 * 3000.0);

	/* pause execution for 0.1 seconds */
        msleep(100L);

        if (stop_button()) {
            /* get out of this while() loop */
            beep();
            break;
        }
    }
    
    /* disables expansion board servo control signals */
    init_expbd_servos(0);

    printf("Press START to  test motor...\n");
    start_press(); /* halt until user presses START */
        
    while (1) {
	/* display the pot value */
        printf("Knob: %d ", knob());

	/* display analog 6 to 2 values */
        for (i= 6; i >=2; i--)
          printf("%d ", analog(i));

	/* print end-of-line so next printf starts from scratch */
        printf("\n");

	/* couple motor 0 speed (-100 - 100) with pot */
	motor(0, (int)(((float)knob() - 128.0) / 128.0 * 100.0));

	/* pause execution for 0.1 seconds */
        msleep(100L);

        if (stop_button()) {
            /* get out of this while() loop */
            beep();
            break;
        }
    }

    /* stop all motors */
    ao();
    
    printf("END; Toggle PWR to try again.\n");
    
}

  

