Advertisement
Guest User

Untitled

a guest
May 11th, 2021
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. /*
  2. Pwm motor control with 2 Potentiometers
  3. laser pwm motor control.ino
  4. Demonstrates use of 2 potentiometers with Arduino and PWM signal.
  5.  
  6. Laser etcher control board 2021
  7.  
  8. */
  9.  
  10.  
  11. // Motor A dual fans
  12. int pwma = 0;
  13.  
  14. // Motor B air pump
  15.  
  16. int pwmb = 1;
  17.  
  18. // Speed control potentiometers
  19.  
  20. int SpeedControl1 = A2;
  21. int SpeedControl2 = A3;
  22.  
  23.  
  24. // Motor Speed Values - Start at zero
  25.  
  26. int MotorSpeed1 = 0;
  27. int MotorSpeed2 = 0;
  28.  
  29. void setup()
  30.  
  31. {
  32.  
  33. // Set all the motor control pins to outputs
  34.  
  35. pinMode(pwma, OUTPUT);
  36. pinMode(pwmb, OUTPUT);
  37.  
  38.  
  39. }
  40.  
  41. void loop() {
  42.  
  43.  
  44.  
  45. // Read the values from the potentiometers
  46.  
  47. MotorSpeed1 = analogRead(SpeedControl1);
  48. MotorSpeed2 = analogRead(SpeedControl2);
  49.  
  50. // Convert to range of 0-255
  51.  
  52. MotorSpeed1 = map(MotorSpeed1, 0, 1023, 0, 255);
  53. MotorSpeed2 = map(MotorSpeed2, 0, 1023, 0, 255);
  54.  
  55. // Adjust to prevent "buzzing" at very low speed
  56.  
  57. if (MotorSpeed1 < 8)MotorSpeed1 = 0;
  58.  
  59. if (MotorSpeed2 < 8)MotorSpeed2 = 0;
  60.  
  61.  
  62. // Set the motor speeds
  63.  
  64. analogWrite(pwma, MotorSpeed1);
  65. analogWrite(pwmb, MotorSpeed2);
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement