Skip to content

Instantly share code, notes, and snippets.

@JosephGregg
Created November 12, 2017 03:19
Show Gist options
  • Save JosephGregg/a3c05dd6f6f883de456fbdd358486c40 to your computer and use it in GitHub Desktop.
Save JosephGregg/a3c05dd6f6f883de456fbdd358486c40 to your computer and use it in GitHub Desktop.
YT-260 Pan/Tilt hack
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
int dataNumber = 0; // new for this version
void setup() {
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(0, OUTPUT);
pinMode(2, OUTPUT);
Serial.begin(115200);
Serial.println("<Pan/Tilt Controller>");
Serial.println("Ready!");
}
void loop() {
recvWithEndMarker();
showNewNumber();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
if (Serial.available() > 0) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewNumber() {
if (newData == true) {
dataNumber = 0;
dataNumber = atoi(receivedChars);
if (dataNumber == 1) {
Serial.println("Received stop command");
analogWrite(5, 0);
analogWrite(4, 0);
exit;
}
else if (dataNumber == 2) {
Serial.println("Received rotate left command");
analogWrite(4, 1023);
digitalWrite(2, LOW);
delay(300);
analogWrite(4, 0);
}
else if (dataNumber == 3) {
Serial.println("Received rotate right command");
analogWrite(4, 1023);
digitalWrite(2, HIGH);
delay(300);
analogWrite(4,0);
}
else if (dataNumber == 4) {
Serial.println("Received tilt back command");
analogWrite(5, 1023);
digitalWrite(0, HIGH);
delay(300);
analogWrite(5,0);
}
else if (dataNumber == 5) {
Serial.println("Received tilt forward command");
analogWrite(5, 1023);
digitalWrite(0, LOW);
delay(300);
analogWrite(5,0);
}
newData = false;
}
}
@jay3702
Copy link

jay3702 commented Jan 21, 2023

Yep, that's the way I would do it now. I found this one not long after fully committing to the hardware-hacking approach: https://hackaday.io/project/175096-hacking-yt-500-pan-tilt-head-radio-remote/details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment