Objective
Control servo rotation through Joystick and get correspsonding rotation of the arrow icon in Scratch.
Principle
Read Joystick X-axis values and get servo rovolve to certain angel according to return values.
Equipment
Hardware Buildup
- Setup 1:Stack CoreUSB and Sensorhub
- Setup 2:Connect Joystick to analog A0 and A1. There is pin description on two sides of Sensorhub,to which you can connect sensors correspondingly.
- Setup 3:Connect servo to D8.
Software Debugging
- Setup 1:Build Scratch programming environment.
- Setup 2:Start programming. Example program download: File:Joystick Servo.zip
- Setup 3:Code description—detect Joystick values for one part and the arrow icon will make correpsonding movement according to Joystick.
- You need to create a variable to save Joystick data.
- Reflect variable values of 0-1023 to 0-180° and control servo through “Motor” plug-in.
- Rotate the arrow according to variables. (Users can change the arrow icon according to individual needs. )
Result
By moving Joystick on X-axis, you can control servo rotation angle.
Video
|