void servoInit() { // set servos to initial positions setServo(PAN, PAN_CENTER); setServo(BOOM, BOOM_UP); setServo(TILT, TILT_FORWARD); setServo(DOOR, DOOR_CLOSED); myDelay(30); setServo(LIFT, LIFT_UP); myDelay(50); disableServo(PAN); disableServo(BOOM); disableServo(TILT); disableServo(DOOR); disableServo(LIFT); }
void setPose(uint8_t pose) { switch (pose) { case DRIVE_OPEN: // set servos to initial positions setServo(PAN, PAN_CENTER); setServo(BOOM, MAX_BOOM_UP); setServo(TILT, TILT_VERT); setServo(DOOR, DOOR_CLOSED); myDelay(30); setServo(LIFT, LIFT_OPEN); myDelay(20); disableServo(PAN); disableServo(BOOM); disableServo(TILT); disableServo(DOOR); disableServo(LIFT); lcdWriteStr("Drive Open", 0, 0); break; case DRIVE_UP: // set servos to initial positions setServo(PAN, PAN_CENTER); setServo(BOOM, BOOM_UP); setServo(TILT, TILT_VERT); setServo(DOOR, DOOR_CLOSED); myDelay(30); setServo(LIFT, LIFT_UP); myDelay(50); disableServo(PAN); disableServo(BOOM); disableServo(TILT); disableServo(DOOR); disableServo(LIFT); lcdWriteStr("Drive UP", 0, 0); break; default: lcdWriteStr("ERROR", 0, 0); break; } }
void everySecond(void) { seconds++; if (seconds > 59) { seconds = 0; everyMinute(); } LED_PORT ^= (1 << LED0); /* blink */ printTime(hours, minutes, seconds); /*serial output */ /* Turn off servo motor after three seconds into new minute */ if (seconds == 3) { disableServo(); } }
int main(void) { //some setup code storePin(1337); //only once needed initPincode(); //initizialize power controle pins initPowerControle(); //initizialize rotary. initRotary(); //initialize shifter. initShifter(); //initialize display code. initDisplay(); //initialize serial comm init_uart(); //initialize the servo code. initServo(); //initialize time code initTime(); //main loop. DDRB |= (1<<PB4)|(1<<PB5); PORTB |= (1<<PB5)|(1<<PB4); while(1) { //get the input from user for pincode getInputPinCode(); //if there is new data we check to see the commands. if(serial_available) { serial_available = 0; runSerialInputCommands(inputStr); } //check the servo state, disable it when it's active //for longer then a second.7 if(isServoActive) //check to see if the state of the servo is active. { if(time-previousServo > timeScale)//see if a second has passed { if(finalServoPos != getCurrentServoState()) { setServoPos(finalServoPos); } else { disableServo(); } } } //send number if logged in and ticks changed and rotary has turned. //to prevent spam if(rotary_has_turned && ticks != previous_ticks && isLoggedIn) { previous_ticks = ticks; rotary_has_turned = 0; sendNumber(pin); } if(timeinSeconds >= 360) { powerOff(); } else { powerOn(); } //if pin is correctly set set green led, else red on. if(pin == actual_pin) { open(); PORTB |= (1<<PB5); PORTB &= ~(1<<PB4); } else { if(!timeinSeconds%2) close(); PORTB |= (1<<PB4); PORTB &= ~(1<<PB5); } } return 1; }