Guest User

Untitled

a guest
Dec 13th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <Adafruit_GFX.h>
  2. #include <Adafruit_SSD1306.h>
  3. #include <Servo.h>
  4.  
  5. #define OLED_RESET 4
  6. Adafruit_SSD1306 display(OLED_RESET);
  7.  
  8. Servo servo9;
  9. Servo servo10;
  10. Servo servo11;
  11.  
  12. void setup() {
  13. Serial.begin(9600);
  14. display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
  15. display.setTextColor(WHITE);
  16. display.stopscroll();
  17. // init done
  18.  
  19. //Set Splash screen
  20. display.clearDisplay();
  21. display.setTextSize(2);
  22. display.print("Servo\nTester");
  23. display.display();
  24. delay(2000);
  25.  
  26. display.clearDisplay();
  27. display.setTextSize(1);
  28. display.setCursor(0,0);
  29. display.print("PWM Pins:\n9,10,11");
  30. display.display();
  31. delay(2000);
  32.  
  33. //Attaches the servo to a pin.
  34. servo9.attach(9);
  35. servo10.attach(10);
  36. servo11.attach(11);
  37.  
  38. display.setTextSize(1);
  39. }
  40.  
  41. void loop() {
  42. int input = 0;
  43. int angle = 0;
  44. display.clearDisplay();
  45. //Read analog value form a0 and set servo values.
  46. input = analogRead(0);
  47. angle = map(input,0,1024,0,180);
  48. servo9.write(angle);
  49.  
  50. display.setCursor(0,0);
  51. display.print("A0:");
  52. display.print( input );
  53. display.setCursor(52,0);
  54. display.print( "PWM-09:");
  55. display.print( angle );
  56.  
  57. //Read analog value form a1 and set servo values.
  58. input = analogRead(1);
  59. angle = map(input,0,1024,0,180);
  60. servo10.write(angle);
  61.  
  62. display.setCursor(0,10);
  63. display.print("A1:");
  64. display.print( input );
  65. display.setCursor(52,10);
  66. display.print( "PWM-10:");
  67. display.print( angle );
  68.  
  69. //Read analog value form a2 and set servo value.
  70. input = analogRead(2);
  71. angle = map(input,0,1024,0,180);
  72. servo11.write(angle);
  73.  
  74. //Display servo 2
  75. display.setCursor(0,20);
  76. display.print("A1:");
  77. display.print( input );
  78. display.setCursor(52,20);
  79. display.print( "PWM-11:");
  80. display.print( angle );
  81. display.display();
  82. delay(100); //Give the servos time to respond not make every.
  83. }
Add Comment
Please, Sign In to add comment