I have written and tested this code.
int speaker = 2;
int led[] = {
9, 10, 11};
int pressure = A1;
const boolean ON = LOW;
const boolean OFF = HIGH;
const boolean RED[] = {
ON, OFF, OFF};
const boolean GREEN[] = {
OFF, ON, OFF};
const boolean BLUE[] = {
OFF, OFF, ON};
void setup() {
Serial.begin(9600);
for(int i = 0; i < 3; i++){
pinMode(led[i], OUTPUT);
}
pinMode(speaker, OUTPUT);
}
void loop() {
int value = analogRead(pressure) / 4;
if((value >= 1) && (value <= 150))
{
setColor(led, GREEN);
digitalWrite(speaker, HIGH);
}
else if(value >= 151)
{
setColor(led, RED);
digitalWrite(speaker, LOW);
}
else
{
setColor(led, BLUE);
digitalWrite(speaker, LOW);
}
Serial.println(value);
delay(100);
}
void setColor(int* led, boolean* color){
for(int i = 0; i < 3; i++){
digitalWrite(led[i], color[i]);
}
}
void setColor(int* led, const boolean* color){
boolean tempColor[] = {
color[0], color[1], color[2] };
setColor(led, tempColor);
}
The issue I have is that I need to use 4 RGB LEDs and 4 sensors, that uses up all of my pins on the Arduino. I have a WS2803 IC that I would like to use for the LEDs but want them to behave the same way as in the code above. Being new to this I am asking for some help on how to write the code to make this happen. I have already downloaded the library for the IC but cant find any examples of how to code it for individual LEDs, not a strip or grid. Thanks for the help.