Created
October 1, 2019 05:14
-
-
Save futureshocked/6fe2858e0aa8fd1d263d37ccc4e8c8a1 to your computer and use it in GitHub Desktop.
08. Arduino servo control oscilloscope demo sketch (Oscilloscopes for Busy People)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 08. Arduino servo control oscilloscope demo sketch | |
| * | |
| * Use this sketch to experiment with the measurement of a PWM waveform | |
| * used to control a servo motor on an oscilloscope. | |
| * | |
| * Connect CH1 of the oscilloscope to pin 9 that controls the servo. | |
| * | |
| * Use a potentiometer to control the duty cycle and therefore the position of the | |
| * servo. | |
| * | |
| * Set triggering to Auto, and start the experiment. | |
| * | |
| * Automatically measure duty cycle, width, frequency and period for the PWM waveform. | |
| * | |
| * Turn on the cursor in auto more and use it to highlight each of the measurements. | |
| * | |
| * This sketch was written for Oscilloscopes for Busy People by Peter Dalmaris. | |
| * Find out more at https://techexplorations.com/courses/oscilloscopes/ | |
| * | |
| * Components | |
| * ---------- | |
| * - Arduino Uno | |
| * - 10 kOhm potentiometer | |
| * - A mini servo motor | |
| * - A breadboard | |
| * - An oscilloscope (of course) | |
| * | |
| * Libraries | |
| * --------- | |
| * - NONE | |
| * | |
| * Connections | |
| * ----------- | |
| * Servo: brown to GND, orange to 5V, yellow to 9. | |
| * Potentiometer: middle pin to A0, one pin to GND, third pin to 5V | |
| * | |
| * | |
| * Other information | |
| * ----------------- | |
| * - | |
| * Created on September 12 2019 by Peter Dalmaris | |
| * | |
| */ | |
| #include <Servo.h> | |
| Servo myservo1; | |
| int servo_pin = 9; | |
| int pos = 0; // variable to store the servo position | |
| int potentiometer = A0; | |
| void setup() { | |
| myservo1.attach(servo_pin); | |
| } | |
| void loop() { | |
| pos = map(analogRead(potentiometer),0,1023,0,255); | |
| myservo1.write(pos); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment