Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ADR - ESP32 AC 220v dimmer arduino demo source code and library
#1
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);
  }*/
}
source code download: 
.zip   tst_dimmer.zip (Size: 744 bytes / Downloads: 73)

AC dimmer arduino library file download: 
.zip   ac-dimmer.zip (Size: 5.68 KB / Downloads: 71)
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)