From 181cc50ffab2878c5554873b861290ec4d596b5c Mon Sep 17 00:00:00 2001 From: AngshuRC <86945275+AngshuRC@users.noreply.github.com> Date: Sun, 9 Jan 2022 11:50:52 +0530 Subject: [PATCH] Add files via upload --- Knob_serial.ino | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Knob_serial.ino diff --git a/Knob_serial.ino b/Knob_serial.ino new file mode 100644 index 0000000..7261b7e --- /dev/null +++ b/Knob_serial.ino @@ -0,0 +1,21 @@ + +#include + +Servo myservo; // create servo object to control a servo + + +String val; +int pos; +void setup() { + myservo.attach(9); + Serial.begin(9600); +} + +void loop() { + if(Serial.available()){ + val = Serial.readString(); // Read String from Serial + pos=val.toInt(); // Converting Serial to Integer + pos=map(pos,0,500,180,0); // maping value from 0 - 500 to 180 - 0 + myservo.write(pos); // finally writing the pulse to the servo + } +}