I've installed LED strips all over the house as sources of light, and I'm trying to controll them with python console(basic program that reads from console and just sends it to serial port), every color and command is accepter except "green", idk why, but in the same line I tried changing command to some random words, and it works...
Arduino NANO btw.
Code:
const int rPin2=3;
const int gPin2=5;
const int bPin2=6;
const int rPin=9;
const int gPin=10;
const int bPin=11;
//
String myCom;
String command;
String com="OK";
//
float dFact=1;
float rBright=255;
float gBright=255;
float bBright=255;
float rBright2=255;
float gBright2=255;
float bBright2=255;
//
void setup() {
Serial.begin(9600);
pinMode(rPin,OUTPUT);
pinMode(gPin,OUTPUT);
pinMode(bPin,OUTPUT);
pinMode(rPin2,OUTPUT);
pinMode(gPin2,OUTPUT);
pinMode(bPin2,OUTPUT);
}
void loop() {
if(Serial.available()){
command = Serial.readStringUntil('/n');
//
if(command.equals("red")){
myCom="red";
command.equals("0");
Serial.println(com);
}else
if(command.equals("green")){
myCom="green";
command.equals("0");
Serial.println(com);
}else
if(command.equals("purple")){
myCom="purple";
command.equals("0");
Serial.println(com);
}else
if(command.equals("all red")){
myCom="2red";
command.equals("0");
Serial.println(com);
}else
if(command.equals("all green")){
myCom="2green";
command.equals("0");
Serial.println(com);
}else
if(command.equals("all white")){
myCom="2white";
command.equals("0");
Serial.println(com);
}else
if(command.equals("all blue")){
myCom="2blue";
command.equals("0");
Serial.println(com);
}else
if(command.equals("white")){
myCom="white";
command.equals("0");
Serial.println(com);
}else
if(command.equals("blue")){
myCom="blue";
command.equals("0");
Serial.println(com);
}else
if(command.equals("red2")){
myCom="red2";
command.equals("0");
Serial.println(com);
}else
if(command.equals("green2")){
myCom="green2";
command.equals("0");
Serial.println(com);
}else
if(command.equals("white2")){
myCom="white2";
command.equals("0");
Serial.println(com);
}else
if(command.equals("blue2")){
myCom="blue2";
command.equals("0");
Serial.println(com);
}else
if(command.equals("alloff")){
myCom="alloff";
command.equals("0");
Serial.println(com);
}else
if(command.equals("off1")){
myCom="off1";
command.equals("0");
Serial.println(com);
}else
if(command.equals("off2")){
myCom="off2";
command.equals("0");
Serial.println(com);
}else
if(command.equals("100")){
myCom="100";
command.equals("0");
Serial.println(com);
}else
if(command.equals("75")){
myCom="75";
command.equals("0");
Serial.println(com);
}else
if(command.equals("50")){
myCom="50";
command.equals("0");
Serial.println(com);
}else
if(command.equals("25")){
myCom="25";
command.equals("0");
Serial.println(com);
}else
if(command.equals("alarm")){
myCom="ALARM";
command.equals("0");
Serial.println(com);
}else{
Serial.println("Invalid Command");
}
}
if(myCom=="alloff"){
rBright=0;
gBright=0;
bBright=0;
rBright2=0;
gBright2=0;
bBright2=0;
}
if(myCom=="red2"){
rBright2=255;
gBright2=0;
bBright2=0;
}
if(myCom=="2red"){
rBright2=255;
gBright2=0;
bBright2=0;
rBright=255;
gBright=0;
bBright=0;
}
if(myCom=="green2"){
rBright2=0;
gBright2=255;
bBright2=0;
}
if(myCom=="2green"){
rBright2=0;
gBright2=255;
bBright2=0;
rBright=0;
gBright=255;
bBright=0;
}
if(myCom=="white2"){
rBright2=255;
gBright2=255;
bBright2=255;
}
if(myCom=="2white"){
rBright2=255;
gBright2=255;
bBright2=255;
rBright=255;
gBright=255;
bBright=255;
}
if(myCom=="blue2"){
rBright2=0;
gBright2=0;
bBright2=255;
}
if(myCom=="2blue"){
rBright2=0;
gBright2=0;
bBright2=255;
rBright=0;
gBright=0;
bBright=255;
}
if(myCom=="red"){
rBright=255;
gBright=0;
bBright=0;
}
if(myCom=="green"){
rBright=0;
gBright=255;
bBright=0;
}
if(myCom=="white"){
rBright=255;
gBright=255;
bBright=255;
}
if(myCom=="blue"){
rBright=0;
gBright=0;
bBright=255;
}
if (myCom=="purple"){
rBright2=255;
gBright2=0;
bBright2=180;
rBright=255;
gBright=0;
bBright=255;
}
if (myCom=="off1"){
rBright=0;
gBright=0;
bBright=0;
}
if (myCom=="off2"){
rBright2=0;
gBright2=0;
bBright2=0;
}
if (myCom=="25"){
dFact=.15;
}
if (myCom=="50"){
dFact=.5;
}
if (myCom=="75"){
dFact=.75;
}
if (myCom=="100"){
dFact=1;
}
if (myCom=="ALARM"){
dFact=1;
gBright=0;
bBright=0;
gBright2=0;
bBright2=0;
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
analogWrite(rPin, fadeValue);
analogWrite(rPin2, fadeValue);
delay(5);
}
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
analogWrite(rPin, fadeValue);
analogWrite(rPin2, fadeValue);
delay(5);
}
}
analogWrite(rPin,rBright*dFact);
analogWrite(gPin,gBright*dFact);
analogWrite(bPin,bBright*dFact);
analogWrite(rPin2,rBright2*dFact);
analogWrite(gPin2,gBright2*dFact);
analogWrite(bPin2,bBright2*dFact);
}
"Pin" and "Pin2" are sections of the house
Can someone please help?