|
Botball 2007
Research Project |
|
|
|
|
|
Code for the Experiment |
// Plant Shade Program
#define shade_arm 0 // Servo port 0
#define sun_sensor 5 // Analog port
5
#define plant_sensor 6 // Analog
port 6
#define shade_opened 170 // Servo
setting for opened shade
#define shade_closed 50 // Servo
setting for closed shade
int main() {
int sun_value = 0;
int plant_value = 0;
int shade_position = 0;
int sun_sum = 0;
int shade_sum = 0;
printf("Cumulative Control\n");
printf("Press A to start, then hold B to stop\n");
while(a_button()==0);
beep();
set_servo_position(shade_arm,shade_opened);
sleep(2.0);
sun_sum = 3000;
while(b_button()==0) {
sun_value = analog(sun_sensor);
plant_value = analog(plant_sensor);
sun_sum = sun_sum-(255-sun_value);
printf("accumulator = %d\n",sun_sum);
if (sun_sum<0) {
// Too much sun
set_servo_position(shade_arm,shade_closed);
sleep(3.0);
// Start the day over again
set_servo_position(shade_arm,shade_opened);
sun_sum = 3000;
}
sleep(1.0);
}
beep();
set_servo_position(shade_arm,shade_opened);
sleep(2.0);
display_clear();
disable_servos();
return 0;
}
|
|
|
|
|