#include <Servo.h>
#define motorPin 9 //For PWM signal
int userInput; //for storing user input
int dutycycle; // for storing duty cycle
void setup()
{
Serial.begin(9600);
pinMode(motorPin,OUTPUT);
Serial.println("Vacuum pump pressure testing using code in which in are taking input from user\n");
Serial.println("Choose an option :- \n");
Serial.print("1. Stop vacuum Pump \n");
Serial.print("2. Start vacuum Pump at 100% duty cycle\n");
Serial.print("3. Run vacuum pump at specific duty cycle\n");
Serial.print("Write 1,2,3 to select any one of these according to your need/choice\n");
}
void loop()
{
while(true)
{
userInput = Serial.parseInt();// exclude newline input due to Enter
//Serial.print("User Input: ");
// Serial.println(userInput);
switch(userInput)
{
case 1:
analogWrite(motorPin,0);
Serial.println("Motor Stopped");
break;
case 2:
analogWrite(motorPin,254);
Serial.println("Motor is running at 100% duty cycle");
break;
case 3:
Serial.println("Enter Duty cycle between 0 to 255 :- ");
while(true)
{
dutycycle = Serial.parseInt();
analogWrite(motorPin, dutycycle);
Serial.println(dutycycle);
}
break;
}
}
}