I am currently using relay module, but I am facing a problem that, when Arduino pins are LOW then all relay are going HIGH, so I want to use this code so that when arduino starts all pins are getting HIGH, and also can be control with char data/switch(data)/case break;/,
Here is my code:
setup() {
if(conditionIsTrue) {
aGroup::setup();
} else {
bGroup::setup();
}
}
loop() {
if(conditionIsTrue) {
aGroup::loop();
} else {
bGroup::loop();
}
}
namespace aGroup {
setup() {
pinMode(ledPinA, OUTPUT);
pinMode(ledPinB, OUTPUT);
pinMode(ledPinC, OUTPUT);
pinMode(ledPinD, OUTPUT);
pinMode(ledPinE, OUTPUT);
pinMode(ledPinF, OUTPUT);
pinMode(ledPinG, OUTPUT);
pinMode(ledPinH, OUTPUT);
pinMode(ledPinI, OUTPUT);
pinMode(ledPinJ, OUTPUT);
pinMode(ledPinK, OUTPUT);
pinMode(ledPinL, OUTPUT);
}
loop() {
digitalWrite(ledPinA, HIGH);
digitalWrite(ledPinB, HIGH);
digitalWrite(ledPinC, HIGH);
digitalWrite(ledPinD, HIGH);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, HIGH);
digitalWrite(ledPinG, HIGH);
digitalWrite(ledPinH, HIGH);
digitalWrite(ledPinI, HIGH);
digitalWrite(ledPinJ, HIGH);
digitalWrite(ledPinK, HIGH);
digitalWrite(ledPinL, HIGH);
}
}
namespace bGroup {
setup() {
Serial.begin(9600);
pinMode(ledPinA, OUTPUT);
pinMode(ledPinB, OUTPUT);
pinMode(ledPinC, OUTPUT);
pinMode(ledPinD, OUTPUT);
pinMode(ledPinE, OUTPUT);
pinMode(ledPinF, OUTPUT);
pinMode(ledPinG, OUTPUT);
pinMode(ledPinH, OUTPUT);
pinMode(ledPinI, OUTPUT);
pinMode(ledPinJ, OUTPUT);
pinMode(ledPinK, OUTPUT);
pinMode(ledPinL, OUTPUT);
}
loop() {
char data = Serial.read();
switch(data)
{
case 'A': digitalWrite(ledPinA, HIGH);break;
case 'B': digitalWrite(ledPinA, LOW);break;
case 'C': digitalWrite(ledPinB, HIGH);break;
case 'D': digitalWrite(ledPinB, LOW);break;
case 'E': digitalWrite(ledPinC, HIGH);break;
case 'F': digitalWrite(ledPinC, LOW);break;
case 'G': digitalWrite(ledPinD, HIGH);break;
case 'H': digitalWrite(ledPinD, LOW);break;
case 'I': digitalWrite(ledPinE, HIGH);break;
case 'J': digitalWrite(ledPinE, LOW);break;
case 'K': digitalWrite(ledPinF, HIGH);break;
case 'L': digitalWrite(ledPinF, LOW);break;
case 'M': digitalWrite(ledPinG, HIGH);break;
case 'N': digitalWrite(ledPinG, LOW);break;
case 'O': digitalWrite(ledPinH, HIGH);break;
case 'P': digitalWrite(ledPinH, LOW);break;
case 'Q': digitalWrite(ledPinI, HIGH);break;
case 'R': digitalWrite(ledPinI, LOW);break;
case 'S': digitalWrite(ledPinJ, HIGH);break;
case 'T': digitalWrite(ledPinJ, LOW);break;
case 'U': digitalWrite(ledPinK, HIGH);break;
case 'V': digitalWrite(ledPinK, LOW);break;
case 'W': digitalWrite(ledPinL, HIGH);break;
case 'X': digitalWrite(ledPinL, LOW);break;
}
}
}
But this isn't work, Please help me.