Guys,
I am asking you to help me with the coding, cause I don't know how to link 2 light effects.
1 light effect: leds with random fading
2 light effect: dimmer light bulb
I want that my input is the volume: microphone as sensor to give me an input. It's a microphone with 4 pins (vcc, ground, one pin to A0, another pin to D7).
I want two lights effects, one it will start with one volume treshold (it's related to the leds on the circuit and it's called rainlight) (here there is only the code of the leds effect)
int LED1 = 6;
int LED2 = 5;
int LED3 = 11;
int LED4 =3;
int LED5 = 9;
int LED6 = 10;
int brightness1 = 0;
int fadeAmount1 = 5;
int fadeAmount2 = 5;
int fadeAmount3 = 5;
int brightness2 = 50;
int brightness3 = 100;
int buttonPoll = 0;
void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
}
void loop() {
{analogWrite(LED1, brightness1);
analogWrite(LED3, brightness2);
analogWrite(LED2, brightness2);
analogWrite(LED5, brightness1);
analogWrite(LED4, brightness3);
analogWrite(LED6, brightness3);
brightness1 = brightness1 + fadeAmount1;
brightness2 = brightness2 + fadeAmount2;
brightness3 = brightness3 + fadeAmount3;
delay(5);//time between updating and writing the brightness variable
}
if (brightness1 <= 0 ||brightness1 >= 255) {
fadeAmount1 = -fadeAmount1;
}else if (brightness2 <= 0 ||brightness2 >= 255){
fadeAmount2 = -fadeAmount2;
}else if (brightness3 <= 0 ||brightness3 >= 255) {
fadeAmount3 = -fadeAmount3;
}
delay(5);
}
and another one will give me the dimmerable light. I have a code when a dimmerable light works with a potentiometer as input. I want to change this putting a microphone as input. So when i talk with a medium volume it will turn on just once my light (gradually), and after 10 seconds it will turn off by herself.
Here there is the code with the potentiometer made by Robojax
#include <RBDdimmer.h>//
//#define USE_SERIAL SerialUSB //Serial for boards whith USB serial port
#define USE_SERIAL Serial
#define outputPin 12
#define zerocross 2 // for boards with CHANGEBLE input pins
#define potPin A0 // define the input pin for potentiometer
/// fix potentiometer issue
const int potMin = 70;// watch video (link above) for details
const int potMax = 804;// watch video (link above) for details
int potValue;// watch video (link above) for details
//dimmerLamp dimmer(outputPin, zerocross); //initialase port for dimmer for ESP8266, ESP32, Arduino due boards
dimmerLamp dimmer(outputPin); //initialase port for dimmer for MEGA, Leonardo, UNO, Arduino M0, Arduino Zero
int outVal = 0;
void setup() {
USE_SERIAL.begin(9600);
dimmer.begin(NORMAL_MODE, ON); //dimmer initialisation: name.begin(MODE, STATE)
}
void loop()
{
potValue =analogRead(potPin);// read potentiometer
correctValue();
// watch video (link above) for details
outVal = map(potValue, 22, 1023, 100, 0); // analogRead(analog_pin), min_analog, max_analog, 100%, 0%);
USE_SERIAL.print("potValue:");
USE_SERIAL.print(potValue);
USE_SERIAL.print(" ");
USE_SERIAL.print(outVal);
USE_SERIAL.println("%");
dimmer.setPower(outVal); // name.setPower(0%-100%)
}
/*
* correctValue()
* Corrects the value for AC dimmer module
* Written by Ahmad Shamshiri on Oct 25, 2019
* watch my Robojax YouTube video vor details
* www.Robojax.com
*/
void correctValue()
{
if(potValue <potMin)
{
potValue =potMin;
}
if(potValue >potMax)
{
potValue =potMax;
}
}//correctValue() end
In the attached image I have copied my attempt to merge the sketches together but I think that the red parts are connected with the potentiometer so I think i might eliminate them.
As I told you I am really new with C++.
Thank you a lot.