#include "lab.h"
#include "esp_log.h"
// Wheels raised for initial tests. Button starts/stops a bounded forward movement.
// Physical motor-power switch remains the independent emergency stop.
void app_main(void) {
    button_init();
    motor_init();
    motor_set(0,0);
    bool running=false;
    int duty=0;
    int64_t stop_at=0;
    TickType_t next=xTaskGetTickCount();
    for(;; ) {
        if(button_pressed()) {
            running=!running;
            stop_at=now_ms()+2000;
        }
        if(now_ms()>=stop_at)running=false;
        if(running) {
            duty+=10;
            if(duty>350)duty=350;
        }
        else duty=0;
        motor_set(duty,duty);
        vTaskDelayUntil(&next,pdMS_TO_TICKS(10));
    }
}
