This small project aims to get the precise values for PWM of servos.
A potentiometer is used to control the servo signal through the arduino,
and the arduino reports the microseconds value to the serial output.
--- /dev/null
+RM := rm -rf
+
+MAINCMD := arduino-cli compile --upload --verify
+
+FQBN := arduino:avr:uno
+PORT := /dev/ttyACM0
+
+MAINCMD += --port $(PORT)
+MAINCMD += --fqbn $(FQBN)
+
+ifneq ("$(wildcard .verbose)","")
+ MAINCMD += --verbose
+endif
+
+SRCS := servotest.ino \
+
+
+NAME := servotest
+
+all : $(NAME)
+
+$(NAME) : .upload
+ arduino-cli monitor --port $(PORT)
+
+.upload : .compile
+ $(MAKE) upload
+ touch .upload
+
+upload : .compile
+ arduino-cli upload --port $(PORT) --verify
+
+.compile : $(SRCS)
+ $(MAKE) compile
+ touch .compile
+
+compile : $(SRCS)
+ arduino-cli compile --fqbn $(FQBN) $<
+
+verbose : .verbose
+
+noverbose :
+ if [ -f .verbose ]; then rm .verbose && $(MAKE) re; fi
+
+re : fclean
+ $(MAKE)
+
+clean :
+
+fclean : clean
+ $(RM) .compile .upload
+
+.% :
+ if [ ! -f $@ ]; then touch $@ && $(MAKE) re; fi
--- /dev/null
+#include <Servo.h>
+
+static const int ANALOG_CONTROL_PIN = A5;
+static const int SERVO_PIN = 6;
+static const int USEC_MIN = 400;
+static const int USEC_MAX = 2700;
+
+static_assert(USEC_MIN <= USEC_MAX, "USEC_MIN cannot be greater then USEC_MAX!");
+
+int main()
+{
+ Servo servo;
+ float signal;
+ int usec;
+
+ init();
+ Serial.begin(9600);
+ servo.attach(SERVO_PIN);
+ while (1)
+ {
+ signal = static_cast<float>(analogRead(ANALOG_CONTROL_PIN)) / ((1 << 10) - 1);
+ usec = signal * (USEC_MAX - USEC_MIN) + USEC_MIN;
+ servo.writeMicroseconds(usec);
+ Serial.println(usec);
+ delay(200);
+ }
+ return (0);
+}