int main(void) { init(); pinMode(13, INPUT); pinMode(LIGHT_SW, INPUT); pinMode(RADIO_SW, INPUT); pinMode(WALL_SW, INPUT); pinMode(LIMIT_UP, INPUT); pinMode(LIMIT_DN, INPUT); pinMode(LIGHT_ON, OUTPUT); pinMode(MOTOR_UP, OUTPUT); pinMode(MOTOR_DN, OUTPUT); //enable watchdog with 2sec reset wdt_enable(WDTO_2S); while(1) { wdt_reset();//reset watchdog before 2sec. // check manual light switch light_sw_set(); // if wall switch is pressed if(wall_sw_set()) toggle_door(); //else is remote pressed ? else if(radio_sw_set()) toggle_door(); //if limit switch hit. Always poll limit switches if(get_limit_up() && door_dir && door_run) toggle_door(); if(get_limit_dn() && !door_dir && door_run) toggle_door(); // timeout if door runs too long if (door_run && (millis() - run_time > MAX_RUN_TIME)) toggle_door(); // timeout if light is on too long if (light_state==HIGH && (millis() - light_time > MAX_LIGHT_TIME)) digitalWrite(LIGHT_ON, (light_state=LOW) ); } return 0; }
// Run the main task: starts the other tasks and controls the back door task main() { // Runs the start-up actions (see actions.c) init(); // Starts taking input from the driver for moving (see drive.c) startTask(drive); startTask(dump_dozer); // Runs the moveable door while(true){ if(vexRT[DOOR_UP_BTN]){ // Call the toggle_door method (in actions.c) to open the door toggle_door(true); }else if(vexRT[DOOR_DOWN_BTN]){ // Call the toggle_door method (in actions.c) to close the door toggle_door(false); } } }
// Runs the start-up stuffs void init(){ toggle_door(true); // Close the back door arcade = false; // Set the default drive mode to tank_drive }