/*_______________________________________________________________ * * U C I C R I T T E R S T U D Y G R O U P * L E S S O N 3 * Working with Parallax Continuous Rotation Servos * Ron Kessler * Created 5/14/2021 * * PURPOSE: * DEMO HOW TO SET CONTINUOUS ROTATION SERVO DIRECTION * WITH SERIAL MONITOR * * Shows how to use serial monitor for intput * * commands: * 1700uSec = CCW Range in microseconds(usec) Full Speed CW 1300>>>>>>>>>>>1500<<<<<<<<<<<<<<1700 Full Speed CCW * 1500usec = STOP * 1300usec = CW * In the serial monitor, type in 1300, 1500, or 1700 to run servo * _______________________________________________________________ */ //---must use servo.h library that comes with Arduino IDE #include //---instantiate new servo object Servo myServo; //--- store current servo direction and define pulse width int myDirection = 1; const int CW = 1300; //1.3ms const int CCW = 1700; //1.7ms const int STOP = 1500; //1.5ms void setup() { //--- initialize serial monitor Serial.begin(9600); myServo.attach(10); // control the servo on pin 10 } void loop() { //---is the serial monitor running? if(Serial.available() > 0) { myDirection = Serial.parseInt(); //read input Serial.println(myDirection); //print code in monitor switch (myDirection) { case 1300: GOclockWise(); break; case 1500: HALT(); break; case 1700: GOcounterClockWise(); break; } } } //************ HELPER FUNCTIONS**************** void GOclockWise() { myServo.write(CW); return; } void GOcounterClockWise() { myServo.write(CCW); return; } void HALT() { myServo.write(STOP); return; }