Hello Everyone! I made a forum post a while ago addressing a problem of mine, but since we finished the basics of the project, I thought it was only necessary if I make a part 2 to my problem. Anyways, I need help with the rgb lights. The rgbs are not responding when I activate their sensor, Oh by the way, what I am trying to do is have 3 rgbs (Final amount will be 30), each have their own sensors hooked up, so when a sensor is activated, the rgb connected to that sensor will activate. However the rgbs won't turn trigger, instead the sensor is triggered Via a sound playing, but the lights won't change color. i want the lights, when the sensor is triggered, to change from a purple color, to a white color. Here is the code. What am I doing wrong?
#include “Arduino.h”
#include “SoftwareSerial.h”
#include “DFRobotDFPlayerMini.h”
int redPin= 7;
int greenPin = 6;
int bluePin = 5;
int redPin2= 4;
int greenPin2 = 3;
int bluePin2 = 2;
int redPin3= 34;
int greenPin3 = 32;
int bluePin3 = 30;
SoftwareSerial mySoftwareSerial(11, 10); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
struct dataLayout
{
byte sensorPin;
byte redPin;
byte greenPin;
byte bluePin;
byte redPin2;
byte greenPin2;
byte bluePin2;
byte redPin3;
byte greenPin3;
byte bluePin3;
boolean active;
};
dataLayout data[9] =
{
{A3, 7, true},
{A3, 6, true},
{A3, 5, true},
{A2, 4, true},
{A2, 3, true},
{A2, 2, true},
{A1, 30, true},
{A1, 32, true},
{A1, 34, true},
};
void setup()
{
mySoftwareSerial.begin(9600);
Serial.println(F(“Initializing DFPlayer … (May take 3~5 seconds)”));
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F(“Unable to begin:”));
Serial.println(F(“1.Please recheck the connection!”));
Serial.println(F(“2.Please insert the SD card!”));
while(true);
}
Serial.println(F(“DFPlayer Mini online.”));
mySoftwareSerial.begin(9600);
Serial.begin(115200);
while (!Serial);
for (int d = 0 ; d < 10; d++)
{
pinMode(data[d].redPin, OUTPUT);
pinMode(data[d].greenPin, OUTPUT);
pinMode(data[d].bluePin, OUTPUT);
pinMode(data[d].redPin2, OUTPUT);
pinMode(data[d].greenPin2, OUTPUT);
pinMode(data[d].bluePin2, OUTPUT);
pinMode(data[d].redPin3, OUTPUT);
pinMode(data[d].greenPin3, OUTPUT);
pinMode(data[d].bluePin3, OUTPUT);
digitalWrite(data[d].redPin, LOW);
digitalWrite(data[d].greenPin, HIGH);
digitalWrite(data[d].bluePin,LOW);//turn on the LED
digitalWrite(data[d].redPin2, LOW);
digitalWrite(data[d].greenPin2, HIGH);
digitalWrite(data[d].bluePin2,LOW);
digitalWrite(data[d].redPin3, LOW);
digitalWrite(data[d].greenPin3, HIGH);
digitalWrite(data[d].bluePin3,LOW);
pinMode(data[d].sensorPin, INPUT_PULLUP);
data[d].active = true;
}
}
void loop()
{
for (int d = 0; d < 9; d++)
{
if (data[d].active)
{
if (digitalRead(data[d].sensorPin))
{
digitalWrite(data[d].redPin, LOW);
digitalWrite(data[d].greenPin, LOW);
digitalWrite(data[d].bluePin, LOW);//turn off the LED
digitalWrite(data[d].redPin2, LOW);
digitalWrite(data[d].greenPin2, LOW);
digitalWrite(data[d].bluePin2, LOW);
digitalWrite(data[d].redPin3, LOW);
digitalWrite(data[d].greenPin3, LOW);
digitalWrite(data[d].bluePin3, LOW);
Serial.println("Motion Detected");
data[d].active = false; //stop further action for this LED
myDFPlayer.volume(30); //Set volume value. From 0 to 30
myDFPlayer.play(6); //Play the first mp3
}
}
}
}