void start_motor(void) { sbi(PORTD, 5); // hack to start mirror even if pwn value is too low to start rotation pwm_ng_set(&pwm, 5000); wait_ms(500); pwm_ng_set(&pwm, get_motor_speed()); }
int main(){ init(); MCUSR &= ~_BV(WDRF); wdt_disable(); get_motor_cnt(); struct motor_state* motors = allocate_motors(); /* while(1){ //PORTD = 0xFF; //PORTD = 0b01010101; //PORTD = 0b00001000;//Pins 3 and 2 show the same value! =( DDRD = 0xFF; PORTD = 0b10100000; } */ unsigned char i; while(1){ current_count = current_count % 100; for (i = 0; i < num_motors; ++i){ if (motor_is_enabled(motors + i) && get_motor_speed(motors + i) > current_count){ USART_transmit(get_motor_speed(motors + i) + 65); activate_motor(i, motors); } else { deactivate_motor(i, motors); } } if (new_motor_state){ memcpy(motors, motor_buf, sizeof(struct motor_state) * num_motors); new_motor_state = 0; USART_transmit('c'); //print_motor_state(motors); } } }