Guys I am new to this forum and I hope I don't break any rules posting the code.
In short I am not a very good with code. I have worked out some code along time ago with a friend on a 1 channel RC switch. I decided to try and do a 5 channel by hacking the 1 channel.
I built a circuit using an ATTINY84 but seem to get no life in the circuit at all with my current code.
Would someone be willing to assist me by looking over the code and pointing me in the right direction.
int ch1;
int ch2;
int ch3;
int ch4;
#define OUTPUT1 1
#define OUTPUT2 2
#define OUTPUT3 3
#define OUTPUT5 5
#define OUTPUT6 6
#define OUTPUT8 8
#define OUTPUT9 9
#define OUTPUT11 11
#define CH_PIN0 0
#define CH_PIN4 4
#define CH_PIN7 7
#define CH_PIN10 10
#define OUT1_THRESHOLD 1775
#define OUT2_THRESHOLD 1775
#define OUT3_THRESHOLD 1300
#define OUT5_THRESHOLD 1775
#define OUT6_THRESHOLD 1300
#define OUT8_THRESHOLD 1775
#define OUT9_THRESHOLD 1300
#define OUT11_THRESHOLD 1300
#define HISTERISIS 20
#define FAILSAFE 40000
void setup()
{
pinMode(CH_PIN0, INPUT);
pinMode(CH_PIN4, INPUT);
pinMode(CH_PIN7, INPUT);
pinMode(CH_PIN10, INPUT);
pinMode(OUTPUT1, OUTPUT);
pinMode(OUTPUT2, OUTPUT);
pinMode(OUTPUT3, OUTPUT);
pinMode(OUTPUT5, OUTPUT);
pinMode(OUTPUT6, OUTPUT);
pinMode(OUTPUT8, OUTPUT);
pinMode(OUTPUT9, OUTPUT);
pinMode(OUTPUT11, OUTPUT);
byte count = 0;
while (count < 20)
{
ch1 = pulseIn(CH_PIN0, HIGH, FAILSAFE);
if ( (ch1 > OUT1_THRESHOLD + HISTERISIS) && (ch1 < OUT11_THRESHOLD - HISTERISIS) )
count++;
else
count = 0;
ch2 = pulseIn(CH_PIN4, HIGH, FAILSAFE);
if ( (ch4 > OUT2_THRESHOLD + HISTERISIS) && (ch4 < OUT3_THRESHOLD - HISTERISIS) )
count++;
else
count = 0;
ch3 = pulseIn(CH_PIN7, HIGH, FAILSAFE);
if ( (ch3 > OUT5_THRESHOLD + HISTERISIS) && (ch3 < OUT6_THRESHOLD - HISTERISIS) )
count++;
else
count = 0;
ch4 = pulseIn(CH_PIN10, HIGH, FAILSAFE);
if ( (ch4 > OUT8_THRESHOLD + HISTERISIS) && (ch4 < OUT9_THRESHOLD - HISTERISIS) )
count++;
else
count = 0;
}
}
void loop()
{
ch1 = pulseIn(CH_PIN0, HIGH, FAILSAFE);
if (ch1 == 0) // 0 = timeout
{
digitalWrite(OUTPUT1, LOW);
digitalWrite(OUTPUT11, LOW);
}
else
{
// On/off detection with histerisis
if (ch1 < OUT1_THRESHOLD)
{
digitalWrite(OUTPUT1, HIGH);
}
else if (ch1 > OUT1_THRESHOLD + HISTERISIS)
{
digitalWrite(OUTPUT1, LOW);
}
// On/off detection with histerisis
if (ch1 < OUT11_THRESHOLD)
{
digitalWrite(OUTPUT11, LOW);
}
else if (ch1 > OUT11_THRESHOLD - HISTERISIS)
{
digitalWrite(OUTPUT11, HIGH);
}
ch2 = pulseIn(CH_PIN4, HIGH, FAILSAFE);
if (ch2 == 0) // 0 = timeout
{
digitalWrite(OUTPUT2, LOW);
digitalWrite(OUTPUT3, LOW);
}
else
{
// On/off detection with histerisis
if (ch2 < OUT2_THRESHOLD)
{
digitalWrite(OUTPUT2, HIGH);
}
else if (ch2 > OUT2_THRESHOLD + HISTERISIS)
{
digitalWrite(OUTPUT2, LOW);
}
// On/off detection with histerisis
if (ch2 < OUT3_THRESHOLD)
{
digitalWrite(OUTPUT3, LOW);
}
else if (ch2 > OUT3_THRESHOLD - HISTERISIS)
{
digitalWrite(OUTPUT3, HIGH);
}
ch3 = pulseIn(CH_PIN7, HIGH, FAILSAFE);
if (ch3 == 0) // 0 = timeout
{
digitalWrite(OUTPUT5, LOW);
digitalWrite(OUTPUT6, LOW);
}
else
{
// On/off detection with histerisis
if (ch3 < OUT5_THRESHOLD)
{
digitalWrite(OUTPUT5, HIGH);
}
else if (ch3 > OUT5_THRESHOLD + HISTERISIS)
{
digitalWrite(OUTPUT5, LOW);
}
// On/off detection with histerisis
if (ch3 < OUT6_THRESHOLD)
{
digitalWrite(OUTPUT6, LOW);
}
else if (ch3 > OUT6_THRESHOLD - HISTERISIS)
{
digitalWrite(OUTPUT6, HIGH);
}
ch4 = pulseIn(CH_PIN10, HIGH, FAILSAFE);
if (ch4 == 0) // 0 = timeout
{
digitalWrite(OUTPUT8, LOW);
digitalWrite(OUTPUT9, LOW);
}
else
{
// On/off detection with histerisis
if (ch4 < OUT8_THRESHOLD)
{
digitalWrite(OUTPUT8, HIGH);
}
else if (ch4 > OUT8_THRESHOLD + HISTERISIS)
{
digitalWrite(OUTPUT8, LOW);
}
// On/off detection with histerisis
if (ch4 < OUT9_THRESHOLD)
{
digitalWrite(OUTPUT9, LOW);
}
else if (ch4 > OUT9_THRESHOLD - HISTERISIS)
{
digitalWrite(OUTPUT9, HIGH);
}
}
}
}
}
}