Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Here's the example code for interfacing the Robotdyn 2-Channel AC Dimmer with an Arduino using the RBDdimmer.h library. This code will allow you to control the brightness of two AC light bulbs independently using the AC dimmer module.
- This code initializes two Robotdyn AC Dimmers on digital pins 2 and 4 (ZC) and 3 and 5 (PWM) using the RBDdimmer library. It also connects two potentiometers to analog pins A0 and A1 to control the dimming levels of the two lights independently. The dimming level ranges from 0 to 100, with 0 being off and 100 being fully on.
- Please note that working with high voltage can be dangerous. Take all necessary precautions and safety measures while working with AC voltage. Also, make sure to check the voltage levels and specifications of your specific board and dimmer before using this code.
- */
- #include <Arduino.h>
- #include <RBDdimmer.h>
- // Pins for the first dimmer
- const int dimmer1Pin = 2; // Digital pin connected to the first AC Dimmer's ZC (zero-cross) pin
- const int pwm1Pin = 3; // Digital pin connected to the first AC Dimmer's PWM pin
- const int pot1Pin = A0; // Analog pin connected to a potentiometer (to control the dimming level of the first light)
- // Pins for the second dimmer
- const int dimmer2Pin = 4; // Digital pin connected to the second AC Dimmer's ZC (zero-cross) pin
- const int pwm2Pin = 5; // Digital pin connected to the second AC Dimmer's PWM pin
- const int pot2Pin = A1; // Analog pin connected to a potentiometer (to control the dimming level of the second light)
- dimmerLamp dimmer1(pwm1Pin, dimmer1Pin); // Initialize the first dimmer
- dimmerLamp dimmer2(pwm2Pin, dimmer2Pin); // Initialize the second dimmer
- void setup() {
- pinMode(pot1Pin, INPUT);
- pinMode(pot2Pin, INPUT);
- dimmer1.begin(NORMAL_MODE, ON); // Start the first dimmer in NORMAL_MODE and turn it ON
- dimmer2.begin(NORMAL_MODE, ON); // Start the second dimmer in NORMAL_MODE and turn it ON
- }
- void loop() {
- int pot1Value = analogRead(pot1Pin);
- int dimmingValue1 = map(pot1Value, 0, 1023, 0, 100);
- dimmer1.setPower(dimmingValue1);
- int pot2Value = analogRead(pot2Pin);
- int dimmingValue2 = map(pot2Value, 0, 1023, 0, 100);
- dimmer2.setPower(dimmingValue2);
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement