Advertisement
vosc3112

DC Motors Activity

Apr 9th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Using a DC Motor
  2.  * 4/9/20
  3.  * Copied from Adafruit website
  4.   */
  5.  
  6.  
  7. int motorPin = 3;
  8.  
  9. void setup()
  10. {
  11.   pinMode(motorPin, OUTPUT);
  12.   Serial.begin(9600);
  13.   while (! Serial);
  14.   Serial.println("Speed 0 to 255");
  15. }
  16.  
  17.  
  18. void loop()
  19. {
  20.   if (Serial.available())
  21.   {
  22.     int speed = Serial.parseInt();
  23.     if (speed >= 0 && speed <= 255)
  24.     {
  25.       analogWrite(motorPin, speed);
  26.     }
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement