03-19-2024, 01:55 AM
Code:
#include <myADR.h> ////RBDdimmer.h /////RBDmcuESP32.h
//Parameters
int zeroCrossPin = 25;
int acdPin = 33;
int add_pin = 15;
int dec_pin = 4;
int MIN_POWER = 0;
int MAX_POWER = 80;
int POWER_STEP = 2;
//Variables
int power = 0;
//Objects
dimmerLamp acd(acdPin,zeroCrossPin);
void setup(){
//Init Serial USB
Serial.begin(115200);
Serial.println(F("Initialize System"));
acd.begin(NORMAL_MODE, ON);
acd.setPower(10); // setPower(0-100%);
Serial.print("lampValue -> ");
Serial.print(acd.getPower());
Serial.println("%");
pinMode(add_pin,INPUT_PULLUP);
pinMode(dec_pin,INPUT_PULLUP);
}
void loop(){
testDimmer();
}
int value = 0;
void testDimmer(){/* function testDimmer */
int add = digitalRead(add_pin);
int dec = digitalRead(dec_pin);
if(add == LOW) value += 1;
if(dec == LOW) value -= 1;
if(value <= MIN_POWER) value = MIN_POWER;
else if(value>MAX_POWER) value = MAX_POWER;
acd.setPower(value);
delay(100);
////Sweep light power to test dimmer
/* for(power=MIN_POWER;power<=MAX_POWER;power+=POWER_STEP){
acd.setPower(power); // setPower(0-100%);
Serial.print("lampValue -> ");
Serial.print(acd.getPower());
Serial.println("%");
delay(100);
}
for(power=MAX_POWER;power>=MIN_POWER;power-=POWER_STEP){
acd.setPower(power); // setPower(0-100%);
Serial.print("lampValue -> ");
Serial.print(acd.getPower());
Serial.println("%");
delay(100);
}*/
}
tst_dimmer.zip (Size: 744 bytes / Downloads: 148)
AC dimmer arduino library file download:
ac-dimmer.zip (Size: 5.68 KB / Downloads: 169)