Professional Documents
Culture Documents
---------------------------------------------------------------------------------------------------------------------------
1|Page
You can get the components needed for this Tilt/Pan
Holder from the links below:
• Frdm KL25Z ………………. Future-e
• Servo Pan / Tilt Bracket Platform………. ram-shop
• 2x Servo motors……………. Future-e
• Jumper Wires…………………. Future-e
// C++ code
//
#include "Servo.h"
2|Page
Servo myservo2(PTC14);
int xPosition = 0;
int yPosition = 0;
int SW_state = 0;
int mapX = 0;
int mapY = 0;
int lastx = 0;
int triger = 1;
int triger2 = 1;
DigitalIn VRx(PTC10);
DigitalIn VRy(PTC11);
DigitalIn SW(PTC12);
if(triger2 == 1) {
for (pos = lasty; pos <= lasty+angele; pos += 10) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo2.write(pos);
if(pos == 120+angele) {
triger2 = 0;
float map(float in, float inMin, float inMax, float outMin, float outMax) {
if (inMin<inMax) {
return outMin;
return outMax;
3|Page
} else { // cope with input range being backwards.
return outMin;
return outMax;
if(triger == 1) {
for (pos = lastx; pos <= angele; pos += 10) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos);
if(pos == angele) {
triger = 0;
int main() {
while(1){
xPosition = VRx;
yPosition = VRy;
SW_state = SW;
triger = 1;
down(mapX);
4|Page
lastx = mapX;
wait(100);
triger2 = 1;
upup(mapY);
lasty = mapY;
wait(100);
if(SW_state == 0) {
triger = 1;
lastx = 0;
down(0);
triger2 = 1;
lasty = 50;
upup(50);
Reference
https://colourtvservicebbsr.blogspot.com/2019/04/diy-
arduino-gimbal-self-stabilizing.html
5|Page