Hello everyone ... I am a novice in the development and adaptation of codes ... I hope someone is willing to help me ... I have this code from the internet, which is a RGB Led lamp and I would like to add an ultrasonic sensor HC-SR04 to the project, I wanted the
Led to be activated at a distance of 30cm and that when I finished lighting all the colors there would be an interval of 2min for it to be activated again, I want to put it in my daughter's room. Thanks for suggestions.
This is the code
/*******************************************************************************
*
- Projeto 20 – Efeito RGB usando 3 leds (criando cores do arco-íris)
-
http://squids.com.br/arduino
*******************************************************************************/
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
setColor(255, 0, 0); // vermelho
delay(1500);
setColor(255, 127, 10); // laranja
delay(1500);
setColor(255, 255, 0); // amarelo
delay(1500);
setColor(0, 255, 0); // verde
delay(1500);
setColor(0, 0, 255); // azul
delay(1500);
setColor(75, 0, 130); // indigo
delay(1500);
setColor(143, 0, 255); // roxo
delay(1500);
setColor(255, 255, 255); // branco
delay(1500);
setColor(255, 0, 255); // magenta
delay(1500);
setColor(0, 255, 255); // ciano
delay(1500);
setColor(0, 0, 0); // preto
delay(1500);
setColor(255, 0, 127); // rosa brilhante
delay(1500);
setColor(255, 105, 180); // rosa forte
delay(1500);
}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}