init_motors();
SetupHardware();
-
+ init_plate_timer();
touchpad_init(); // you need to call this to setup the I/O pin!
_delay_ms(500);
sei();
while (1) {
Usb2SerialTask();
parse_command(); // read data from virtual comport
- touchpad_read(); // read data from touchpad
- inc_target_plate_pos_x(4*delta_x());
- inc_target_plate_pos_y(-4*delta_y());
- if(move_plate()){
+// touchpad_read(); // read data from touchpad
+// inc_target_plate_pos_x(4*delta_x());
+// inc_target_plate_pos_y(-4*delta_y());
+ if(plate_ready()){
pos_report();
}
}
#include <avr/io.h>
#include <stdlib.h>
+#include <avr/interrupt.h>
#include <util/delay.h>
#include "motors.h"
#include "plate.h"
int32_t plate_pos_x = 0,plate_pos_y = 0;
int32_t target_plate_pos_x = 0,target_plate_pos_y = 0;
+uint8_t ready = 0;
+
int32_t get_plate_pos_x(void){
return plate_pos_x;
}
target_plate_pos_y += value;
}
+uint8_t plate_ready(void){
+ if(ready){
+ ready = 0;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+
uint8_t move_plate(void){
int32_t todo_x,todo_y = 0;
+void init_plate_timer(void){
+ TCCR1B |= (1<<CS10) | (1<<CS12) | (1<<WGM12);
+ TCCR1C |= (1<<FOC1A);
+ OCR1A = 32;
+ TIMSK1 |= (1<<OCIE1A);
+
+}
-
+ISR( TIMER1_COMPA_vect ) {
+ if(move_plate()){
+ ready = 1;
+ }
+}
uint8_t move_plate(void);
+uint8_t plate_ready(void);
-
-
-
+ISR( TIMER1_COMPA_vect );
+void init_plate_timer(void);
int32_t get_plate_pos_x(void);
int32_t get_plate_pos_y(void);
void set_plate_pos_x(int32_t value);