Signed in as:
filler@godaddy.com
Signed in as:
filler@godaddy.com
Using two 9 gram Servos, a Joystick, Breadboard Power + Raspberry Pi PICO to control a 3D printed Platform.
Allowing for Granular Pan/Tilt Control of a platform using xyz controls.
Download below contains the code and the libraries used.
#include <Servo.h>
const int xpin = 28;
const int ypin = 27;
const int zpin = 26;
const int xservo = 17;
const int yservo = 16;
int ystate;
int xstate;
int zstate;
int sstate;
Servo my_xservo; //Create servo control object
Servo my_yservo; //Create servo control object
void setup() {
pinMode(ypin, INPUT);
pinMode(xpin, INPUT);
pinMode(zpin, INPUT);
my_xservo.attach(xservo); //Attaches the servo
my_yservo.attach(yservo); //Attaches the servo
Serial.begin(9600); //Start Serial
}
void loop(){
xstate = analogRead(xpin); //Get X State
ystate = analogRead(ypin); //Get Y State
zstate = analogRead(zpin); //Get Z State
Serial.println("X,Y,Z: " + String(xstate) + ", " + String(ystate) + ", " + String(zstate) + ", ""ServoVal: " + String(sstate)); //Outputs to Serial monitor
delay(10);
sstate = analogRead(xpin);
sstate = map(sstate, 0, 1023, 0, 90); //maps the servo values to postion my_xservo.write(sstate); //writes the map to the X servo
delay(15); //allows the servo to catch up
sstate = analogRead(ypin);
sstate = map(sstate, 0, 1023, 0, 180); //maps the servo values to postion my_yservo.write(sstate); //writes the map to the Y servo
delay(15); //allows the servo to catch up
}