I am trying to read the the PPM output from one Arduino and display the output on another.
There are only two different signals sent out
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 //OFF
Or
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1, 0, 1, 0, 1, 1, 1, 1, 0, 0 //ON
The code that sends them is below, I had hoped it would simply be a case of a common ground and digital out on master connected to digital in on the slave and then DigitalRead that pin and then receive one of the strings above....how wrong could I have been ?
I am getting various readings, none of which relate to data sent.
Does anyone please have a start up example I could use as my foundation
#define transmitPin 4 // Digital Pin 4
// on
bool data[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 1, 0, 1, 1, 1, 1, 0, 0
};
// off
//bool data[] = {
// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
//};
int shortDelay = 250;
int longDelay = 500;
int preambleDelay = 1000;
void setup() {
Serial.begin(9600);
pinMode(transmitPin, OUTPUT);
delay(3000);
}
void loop() {
sendPreamble();
sendData();
sendPreamble();
sendData();
delay(30000);
}
void sendPreamble() {
for (int i = 0; i < 4; i++) {
digitalWrite(transmitPin, HIGH);
delayMicroseconds(preambleDelay);
digitalWrite(transmitPin, LOW);
delayMicroseconds(preambleDelay);
}
}
void sendData() {
for (int i = 0; i < sizeof(data); i++) {
bool b = data[i];
if (b == 1) {
digitalWrite(transmitPin, HIGH);
delayMicroseconds(longDelay);
digitalWrite(transmitPin, LOW);
delayMicroseconds(shortDelay);
} else {
digitalWrite(transmitPin, HIGH);
delayMicroseconds(shortDelay);
digitalWrite(transmitPin, LOW);
delayMicroseconds(longDelay);
}
}
}