#include <stdio.h>
#include <math.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "hardware/timer.h"
const uint8_t PIN_A = 11; // GPIO pin connected to encoder A
const uint8_t PIN_B = 12; // GPIO pin connected to encoder B
void send_pulse(uint pin, uint32_t delay_us) {
gpio_put(pin, 1);
sleep_us(delay_us);
gpio_put(pin, 0);
}
void rotate_encoder(int steps) {
for (int i = 0; i < abs(steps); ++i) {
// Simulate a falling edge on pin A followed by a falling edge on pin B
send_pulse(PIN_A, 100); // Adjust the delay as needed
send_pulse(PIN_B, 100); // Adjust the delay as needed
}
}
int main() {
stdio_init_all();
gpio_init(PIN_A);
gpio_init(PIN_B);
gpio_set_dir(PIN_A, GPIO_OUT);
gpio_set_dir(PIN_B, GPIO_OUT);
// Simulate rotating the encoder four points to the left
rotate_encoder(-4);
return 0;
}