Hi all,
I hope I'm posting this in the correct forum and please excuse the fact that I'm not experienced at coding.
I am trying to control a series of led strips using 8 digital pins on an Arduino Pro mini. The input device to control these is a single PPM signal from an RC receiver.
So basically I have the PPM signal being read using pulseIn on pin 5. This channel is connected to a three position switch. This is all working fine so far.
I then want to control the output of pins 6 to 13 HIGH or LOW based on the values from pulseIn. eg. position 1 all pins HIGH, position 2 pins 11 & 13 HIGH all other pins LOW.
I can get this working for one position but if I try to add another position it behaves erraticaly.
I would appreciate it if someone could guide me as to what I should do to fix this.
Many Thanks
int ch1;
int white_a = 13;
int white_b = 12;
int green_a = 11;
int green_b = 10;
int blue_a = 9;
int blue_b = 8;
int red_a = 7;
int red_b = 6;
void setup() {
pinMode(5, INPUT);
Serial.begin(9600);
pinMode(white_a, OUTPUT);
pinMode(white_b, OUTPUT);
pinMode(green_a, OUTPUT);
pinMode(green_b, OUTPUT);
pinMode(blue_a, OUTPUT);
pinMode(blue_b, OUTPUT);
pinMode(red_a, OUTPUT);
pinMode(red_b, OUTPUT);
}
void loop() {
ch1 = pulseIn(5, HIGH, 20000); // Read the pulse width of channel 5
//Sequence 1
if (ch1 >= 900 && ch1 <= 990)
{digitalWrite(white_a, HIGH);}
else
{digitalWrite(white_a, LOW);}
if (ch1 >= 900 && ch1 <= 990)
{digitalWrite(white_b, HIGH);}
else
{digitalWrite(white_b, LOW);}
if (ch1 >= 900 && ch1 <= 990)
{digitalWrite(green_a, HIGH);}
else
{digitalWrite(green_a, LOW);}
if (ch1 >= 900 && ch1 <= 990)
{digitalWrite(green_b, HIGH);}
else
{digitalWrite(green_b, LOW);}
if (ch1 >= 900 && ch1 <= 990)
{digitalWrite(blue_a, HIGH);}
else
{digitalWrite(blue_a, LOW);}
if (ch1 >= 900 && ch1 <= 990)
{digitalWrite(blue_b, HIGH);}
else
{digitalWrite(blue_b, LOW);}
if (ch1 >= 900 && ch1 <= 990)
{digitalWrite(red_a, HIGH);}
else
{digitalWrite(red_a, LOW);}
if (ch1 >= 900 && ch1 <= 990)
{digitalWrite(red_b, HIGH);}
else
{digitalWrite(red_b, LOW);}
// Sequence 2
if (ch1 >= 1000 && ch1 <= 1800)
{digitalWrite(white_a, HIGH);}
else
{digitalWrite(white_a, LOW);}
if(ch1>1000)
{digitalWrite(white_b, HIGH);}
else
{digitalWrite(white_b, LOW);}
if(ch1>1000)
{digitalWrite(green_a, HIGH);}
else
{digitalWrite(green_a, LOW);}
if(ch1>1000)
{digitalWrite(green_b, HIGH);}
else
{digitalWrite(green_b, LOW);}
if(ch1>1000)
{digitalWrite(blue_a, HIGH);}
else
{digitalWrite(blue_a, LOW);}
if(ch1>1000)
{digitalWrite(blue_b, HIGH);}
else
{digitalWrite(blue_b, LOW);}
if(ch1>1000)
{digitalWrite(red_a, LOW);}
else
{digitalWrite(red_a, LOW);}
if(ch1>1000)
{digitalWrite(red_b, LOW);}
else
{digitalWrite(red_b, LOW);}
Serial.print("PWM:");
Serial.println(ch1);
delay(100);
}