-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbasic_example.ino
More file actions
70 lines (51 loc) · 2.1 KB
/
basic_example.ino
File metadata and controls
70 lines (51 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Basic Example.
This sketch alternately fades two lights in and out, using a
digital mains AC dimmer switch board.
This sketch is meant to be used with one of these boards, or
something similar:
https://www.amazon.com/Dimmer-Module-Controller-Arduino-Raspberry/dp/B06Y1GVG26
https://mdwdz.en.alibaba.com/product/60670737878-804998378/2CH_AC_LED_Light_Dimmer_Module_Controller_Board.html
http://www.inmojo.com/store/krida-electronics/item/2-channel-ac-led-bulb-dimmer-module-v2/
While this sketch is meant to be used with a dual-channel dimmer,
it can also control just a single channel (just leave the second
channel disconnected).
Note that the circuit here uses high-voltage mains AC power - make
sure you understand the risks and take appropriate precautions.
The circuit:
* Pin 8 is connected to the dimmer 'sync' pin.
* Pin 9 is connected to the dimmer 'ch 1' pin.
* Pin 10 is connected to the dimmer 'ch 2' pin.
* The dimmer power input is connected to mains AC power.
* The dimmer channel 1 and channel 2 outputs are connected
to lightbulbs or other devices.
Created 2017-02-23
By Anson Mansfield
*/
#include <TriacDimmer.h>
// arduino pins
unsigned char sync = 8; //sync pin
unsigned char channel_1 = 9; // channel 1 pin
unsigned char channel_2 = 10; // channel 2 pin
void setup() {
// initialize the dimmer library.
TriacDimmer::begin();
}
void loop() {
// gradually increase brightness over time
for(float brightness = 0.00; brightness < 1.00; brightness += 0.01){
// set channel 1 to the brightness value:
TriacDimmer::setBrightness(channel_1, brightness);
// invert brightness for channel 2:
TriacDimmer::setBrightness(channel_2, 1 - brightness);
delay(20);
}
// and back down - decrease brightness over time
for(float brightness = 1.00; brightness > 0.00; brightness -= 0.01){
// set channel 1 to the brightness value:
TriacDimmer::setBrightness(channel_1, brightness);
// invert brightness for channel 2:
TriacDimmer::setBrightness(channel_2, 1 - brightness);
delay(20);
}
}