Hoping someone can help out with any mistake that has been made ,
Im using James Bruton (XRobots on youtube) latest transmitter code and im having issues to where channels 7-10 are not outputting on the PPM stream ,
I tried using ChatGPT to add the 4 switch functions , but its not working
Im trying to get channel 7-10 to operate using 3 position switches and to send that out on the PPM so that the received servos would rotate as 0 deg when switch low , 180 deg when switch high , and 90 degree when switch is in midpoint
Hope this makes sense as its confusing the heck out of me lol
The code so far is as follows
// sends ten channels of PPM by bit banging.
int ch1 = 1500; // initial values
int ch2 = 1550;
int ch3 = 1500;
int ch4 = 1500;
int ch5 = 1500;
int ch6 = 1500;
int ch7 = 1500;
int ch8 = 1500;
int ch9 = 1500;
int ch10 = 1500;
// switch input pins
const int switch1 = 2;
const int switch2 = 3;
const int switch3 = 4;
const int switch4 = 5;
void setup() {
pinMode(9, OUTPUT); // PPM output pin
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(switch3, INPUT);
pinMode(switch4, INPUT);
Serial.begin(115200); // debug
}
void loop() {
ch1 = analogRead(A0); // read analog sticks
ch1 = map(ch1, 0, 1023, 1000, 2000);
ch2 = analogRead(A1);
ch2 = map(ch2, 0, 1023, 1000, 2000);
ch3 = analogRead(A2);
ch3 = map(ch3, 0, 1023, 1000, 2000);
ch4 = analogRead(A3);
ch4 = map(ch4, 0, 1023, 1000, 2000);
ch5 = analogRead(A4);
ch5 = map(ch5, 0, 1023, 1000, 2000);
ch6 = analogRead(A5);
ch6 = map(ch6, 0, 1023, 1000, 2000);
// read the switch positions
int switchPos1 = digitalRead(switch1);
int switchPos2 = digitalRead(switch2);
int switchPos3 = digitalRead(switch3);
int switchPos4 = digitalRead(switch4);
// assign the corresponding channel values based on the switch positions
if (switchPos1 == LOW) {
ch7 = 1000;
} else if (switchPos1 == HIGH) {
ch7 = 2000;
}else {
ch7 = 1500;
}
if (switchPos2 == LOW) {
ch8 = 1000;
} else if (switchPos2 == HIGH) {
ch8 = 2000;
}else {
ch8 = 1500;
}
if (switchPos3 == LOW) {
ch9 = 1000;
} else if (switchPos3 == HIGH) {
ch9 = 2000;
}else {
ch9 = 1500;
}
if (switchPos4 == LOW) {
ch10 = 1000;
} else if (switchPos4 == HIGH) {
ch10 = 2000;
}else {
ch10 = 1500;
}
digitalWrite(9, HIGH);
delayMicroseconds(500); // pulse
digitalWrite(9, LOW);
delayMicroseconds(ch1 - 500); // gap for the remaining period
digitalWrite(9, HIGH);
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(ch2 - 500);
digitalWrite(9, HIGH);
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(ch3 - 500);
digitalWrite(9, HIGH);
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(ch4 - 500);
digitalWrite(9, HIGH);
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(ch5 - 500);
digitalWrite(9, HIGH); // ch6
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(ch6 - 500);
digitalWrite(9, HIGH); // ch7
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(1000 - 500);
digitalWrite(9, HIGH); // ch8
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(1100 - 500);
digitalWrite(9, HIGH); // ch9
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(1200 - 500);
digitalWrite(9, HIGH); // ch10
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(1300 - 500);
digitalWrite(9, HIGH); // sync pulse
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(5000); // longer gap
}