Example #1
0
/*---------------------------------------------------------------------------*/
static int
configure(int type, int c)
{
  switch(type) {
  case SENSORS_ACTIVE:
    if(c) {
      if(!status(SENSORS_ACTIVE)) {
	servo_init();
        enabled = 1;
      }
    } else {
      servo_off();
      enabled = 1;
    }
    break;
  case SERVO_SENSOR_A:
    servo_set(0,c);
    break;
  case SERVO_SENSOR_B:
    servo_set(1,c);
    break;
  }
  return 0;
}
Example #2
0
void frob_outputs()
{
    char a[6][10]= {"Motors","LEDs","Servo","IR on","IR off","Quit"};
    int sel,port,index;

    while(1)
    {
        if((index=select_string(a,5))==-1)
            return;

        if(index==0) /* motors */
            while(1)
            {
                if((port=select_int_value("Motor ",0,5))==-1)
                    break;

                while(chosen_button()==NEITHER_B)
                {
                    sel=frob_knob()-128;

                    if(sel>100)
                        sel=100;
                    else if(sel<-100)
                        sel=-100;

                    motor(port,sel);
                }

                off(port);

                if(chosen_button()==ESCAPE_B)
                    break;
            }
        else if(index==1)  /* LEDS */
        {
            char ch[5][10]= {"Led 0 off","Led 0 on","Led 1 off",
                             "Led 1 on","Quit"
                            };

            while(1)
            {
                if((sel=select_string(ch,5))==-1)
                    break;

                if(sel==0) led_out0(0);
                else if(sel==1) led_out0(1);
                else if(sel==2) led_out1(0);
                else if(sel==3) led_out1(1);
                else
                    return;
            }
        }
        else if(index==2) /* servo */
        {
            servo_on();

            while(chosen_button()==NEITHER_B)
            {
                sel=(frob_knob()*10)+700;
                servo(sel);
            }

            servo_off();

            if(chosen_button()==ESCAPE_B)
                break;
        }
        else if(index==3) /* IR on */
            ir_transmit_on();
        else if(index==4) /* IR off */
            ir_transmit_off();
        else   /* Quit */
            return;
    }
}