11. Input devices¶
Group 1 (Ito-Yamada)¶
This is the group assignment of the week.
- probe an input device’s analog levels and digital signals
In this Group Assignment, we will control the servo motor used in Week 9’s Individual Assignment with a volume switch and observe the signal using an oscilloscope. The control panel is equipped with many switches, which seem quite challenging to master. Initially, we will receive a lecture on how to use the oscilloscope from our instructor.
Next, to confirm our understanding, we will actually perform the same tasks ourselves.
The oscilloscope we will use is the FNIRSI DSO-TC3.
The execution environment will be the same as explained during the lecture, using a breadboard connected to a SG90 servo motor, RP2040, and a volume switch. Finally, all that is left is to connect the oscilloscope to the analog inputs and digital outputs, and then we are ready to begin.
Download sample program:
File->Examples->Servo->Sweep
I updated the pin number in the source code from 9 to 6 to reflect the servo being connected to pin 6.
/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = A0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
myservo.attach(6); // attaches the servo on pin 6 to the servo object
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it for use with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
After executing the program, we will turn the Volume Switch clockwise and observe the changes in the waveform.
By turning the adjustment knob, the pulse width is changed, which is used for controlling the position of the servo motor.