#include <stdio.h>
#include <math.h>
#include "pico/stdlib.h"
#include "hardware/adc.h"
#include "hardware/dma.h"
const int potPin = 26;
const uint forwardPin = 1;
const uint reversePin = 2;
#define OFF 0
#define ON 1
const uint MAX_SLIDER_VALUE = 4096;
const uint DEAD_ZONE_WIDTH = 100;
// variable for storing the potentiometer value
int potValue = 0;
void setup() {
Serial.begin(115200);
analogReadResolution(12);
gpio_init(forwardPin);
gpio_init(reversePin);
gpio_set_dir(forwardPin, GPIO_OUT);
gpio_set_dir(reversePin, GPIO_OUT);
}
void loop() {
sleep_ms(100);
// Reading potentiometer value
potValue = analogRead(potPin);
Serial.println(potValue);
if (isInDeadZone(potValue)) {
gpio_put(forwardPin, OFF);
gpio_put(reversePin, OFF);
} else {
if (potValue > (MAX_SLIDER_VALUE / 2)) {
gpio_put(forwardPin, ON);
gpio_put(reversePin, OFF);
} else {
gpio_put(forwardPin, OFF);
gpio_put(reversePin, ON);
}
}
}
bool isInDeadZone(uint potV) {
if (potV > ((MAX_SLIDER_VALUE / 2) - (DEAD_ZONE_WIDTH)) && )
}