Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int motorOut = 9;
- void setup() {
- pinMode(motorOut, OUTPUT);
- Serial.begin(9600);
- while(! Serial)
- {
- Serial.println("Speed = 0 to 255");//user prompt for speed
- }
- }
- void loop() {
- if(Serial.available() > 0)
- {
- int motorSpeed = Serial.parseInt();//takes input from the serial monitor
- if(motorSpeed >= 1 && motorSpeed <= 255)//ensures a value that is usable
- {
- analogWrite(motorOut, motorSpeed);
- }
- else if(motorSpeed == -1)//command to stop movement
- {
- analogWrite(motorOut, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement