void cmd_interpreter( void *xBoard,int pressed_key) { // ================================================ //printf("I am inside cmd_interpreter() before switch. \n"); switch (pressed_key) { case 117: // pressed_key char = u or int = 117 // DRIVE CNC ALONG Y-AXIS printf("u \tdrive_up (500) y-axis (12,8 CW)\t==> Y-axis PINS = (0)(0) (1/0)(1) (0)(0) running ... "); drive_up(xBoard, 500); // DRIVE (12,8 CW) printf("done.\n"); break; case 100: // pressed_key char = d or int = 100 // DRIVE CNC ALONG Y-AXIS printf("d \tdrive_down (500) y-axis (4,0 CCW)\t==> Y-axis PINS = (0)(0) (1)(0) (0)(0) running ... "); drive_down(xBoard, 500); // DRIVE (4,0 CCW) printf("done.\n"); break; case 114: // pressed_key char = r or int = 114 // DRIVE CNC ALONG X-AXIS printf("r \tdrive_right (500) x-axis (3,2 CW)\t==> X-axis PINS = (1/0)(1) (0)(0) (0)(0) running ... "); drive_right(xBoard, 500); // DRIVE (3,2 CW) printf("done.\n"); break; case 108: // pressed_key char = l or int = 108 // DRIVE CNC ALONG X-AXIS printf("l \tdrive_left (500) x-axis (1,0 CCW)\t==> X-axis PINS = (1)(0) (0)(0) (0)(0) running ... "); drive_left(xBoard, 500); // DRIVE (1,0 CCW) printf("done.\n"); break; case 122: // pressed_key char = z or int = 122 // DRIVE CNC ALONG Z-AXIS printf("z \tdrivepen_up (500) z-axis (16,0 CW)\t==> Z-axis PINS = (0)(0) (0)(0) (1)(0) running ... "); pen_up(xBoard, 500); // DRIVE (16,0 CW) printf("done.\n"); break; case 115: // pressed_key char = s or int = 115 // DRIVE CNC ALONG Z-AXIS printf("s \tdrivepen_down(500) z-axis (48,32 CCW)\t==> Z-axis PINS = (0)(0) (0)(0) (1/0)(1) running ... "); pen_down(xBoard, 500); // DRIVE (48,32 CCW) printf("done.\n"); break; //=========== case 113: // pressed_key char = q or int = 113 // QUIT AND EXIT PROGRAM printf("q \tQuit and exit. \t\t==> Alhamdulillah. Done. \n\n"); // reset_CNC(); // RELEASE IO_PORTADDRESS WITH VALUE 0 printf("Alhamdulillah. Parallel port successfully released. \n\n"); close_keyboard(); exit(0); default: printf("%c \tERROR: Invalid command: ==> char %c or int %d \n", pressed_key, pressed_key, pressed_key); } //printf("I am exiting cmd_interpreter() after switch. \n"); }
int main(void) { //setting PWM-Ports as output DDRB = 0xFF; //set port B as output DDRD = 0b11111101; //set port D as output with pin D1 input //setup the pwm for the servo TCCR1A = _BV(COM1A1) // set OC1A/B at TOP | _BV(COM1B1) // clear OC1A/B when match | _BV(WGM11); //(fast PWM, clear TCNT1 on match ICR1) TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11); // timer uses main system clock with 1/8 prescale ICR1 = 20000; // used for TOP, makes for 50 hz PWM OCR1A = 1500; // servo at center //set up pwm for the motors TCCR0A = _BV(COM0A1) // set OC1A/B at TOP | _BV(COM0B1) // clear OC1A/B when match | _BV(WGM00) // fast PWM mode | _BV(WGM01); TCCR0B = _BV(CS01) | _BV(CS00); drive_stop(0); //motors stopped servo_position(servo_center, 50); //servo center //variables to hold the distances; uint16_t forward_dist; uint16_t left_dist; uint16_t right_dist; uint8_t fwd_count; servo_position(servo_center, 50); while(1) { forward_dist = sensor_distance(); _delay_ms(50); if (forward_dist <= forward_buffer) { drive_stop(0); beep_meow(); servo_position(servo_left, 400); left_dist = sensor_distance(); servo_position(servo_right,400); right_dist = sensor_distance(); servo_position(servo_center,200); while ((left_dist > right_dist) && (forward_dist <= (forward_buffer + now_clear))) { drive_left(speed_80p); forward_dist = sensor_distance(); _delay_ms(50); } while ((left_dist <= right_dist) && (forward_dist <= (forward_buffer + now_clear))) { drive_right(speed_80p); forward_dist = sensor_distance(); _delay_ms(50); } } drive_forward(speed_80p); fwd_count++; if (fwd_count == 20) { fwd_count = 0; servo_position(servo_left, 150); left_dist = sensor_distance(); if (left_dist <= sides_buffer) { drive_stop(0); beep_meow(); while (left_dist <= (sides_buffer + now_clear)) { drive_right(speed_80p); left_dist = sensor_distance(); _delay_ms(100); } } servo_position(servo_center,100); servo_position(servo_right, 150); right_dist = sensor_distance(); if (right_dist <= sides_buffer) { drive_stop(0); beep_meow(); while (right_dist <= (sides_buffer + now_clear)) { drive_left(speed_80p); right_dist = sensor_distance(); _delay_ms(100); } } servo_position(servo_center,100); } } return 0; }