-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenLight_DM4DS_v1_1-Channel_PMW.ino
149 lines (123 loc) · 5.88 KB
/
OpenLight_DM4DS_v1_1-Channel_PMW.ino
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// OpenLight (GPL v3) + no commercial use without permission! Free to modify but you have to name me in your project.
// share alike / this is also for the 3D Printed parts, not only the arduino code. Thanks and enjoy it!
//
// I am sure this will be updated from time to time, so come back for the updates.
// The/a free programmable UniLight (Copyright by https://www.unilight.at/) and modifyable for your needs! Open Source.
// to realise Light schemes to your vehicle - plane - truck - crawler - boot - etc.
// it is based on Arduino (https://www.arduino.cc/) - in my case I use a Arduino Micro 5V
// to power it straight from the 5V Servo port of my Receiver. Just plug it in and the arduino
// is doing its job.
//
//
// How does it work:
// On the "PWMInput1" Pin (in my case D9) the PWM from the receiver is read
// with a following IF the position of your source / switch is detected and translated in
// a specific blink scheme / perma light if you want (but look for the heat if you are using high power LED).
//
// In the example:
// full low < 1200 uS = no light at all
// mid range >1200 <1600 = slow blinking
// high range >1600 = fast blinking
// /feel free to express yourself in building your own blink schemes by adjusting the timings.
//
// while the LED´s generating a lot of heat if the are turned on for long time, I only switch them on
// for 10 mS! That is enough to get the needed flash and stay cool, but feel free to modify it for your needs!
// In the example only LED1 Pin 3 is connected as output to a MosFET Board, but I already defined 4 / 5 also if you need them
// copy & paste the code and change the LED1 to LED2 / LED3.
//
// As I said, I use a 5V Arduino Micro, so I can connect it straight to a free RX channel for the PWM Signal + 5V to power
// the Arduino. Win win :)
// no special lybraries are needed, so it should be fine to use "almost" any Arduino you have laying around. Try it.
//
// watch in the serial monitor/plotter your RX input. If there is nothing detected, it can´t work.
// I had the case that with a cheap SERVO TESTER it was not working, but with a actuall RX it is always 100% working!
// So I looked with the oscilloscope on the PWM of the Servo tester and omg, that was distorted and no wonder it was not working.
// Keep that in mind, if you maybe test on the bench.
//
// now - let´s blink :)
// DM4DS - Sandor
//
int LED1 = 3; // that´s the one output I´m using and is configured to blink as above described
// int LED2 = 4; // alternative outputs if you wanna usw it for more unique lighting / uncomment -
// int LED3 = 5; // copy & paste the IF /digitalwrite line + insert LED2/3 instead of LED1
int PWMInput1 = 9; // PWM Input from the Receiver
void setup() {
pinMode(LED1, OUTPUT); // define LED1 Pin as output
// pinMode(LED2, OUTPUT); // uncomment if needed
// pinMode(LED3, OUTPUT); // "
pinMode(PWMInput1, INPUT); // PWMINput1 defined as input from the RX - if you need more inputs, feel free to define more
Serial.begin(115200); // Serial Monitor / Plotter setting
}
void loop() { // here the magic happens
int pwm1 = pulseIn(PWMInput1, HIGH);
Serial.println(pwm1); // Serial Monitor / Plotter Output
if(pwm1 < 1199) // If the stick / switch is under 1200 (low) do "no blinking"
{
Serial.print(PWMInput1);
digitalWrite(LED1, LOW);
delay(250);
digitalWrite(LED1, LOW);
delay(500);
}
else
{
Serial.print(PWMInput1);
}
if(pwm1 > 1801) // if the stick / switch is over 1800 (full up/on) fast blinking
{
Serial.print(PWMInput1);
digitalWrite(LED1, HIGH);
delay(10);
digitalWrite(LED1, LOW); // fast blinking while the pause between the blinks is shorten than in the last case
delay(150);
digitalWrite(LED1, HIGH);
delay(10);
digitalWrite(LED1, LOW); // half a second break before it starts again with fast blinking
delay(500);
}
else
{
Serial.print(PWMInput1);
}
if((pwm1 < 1800)&&(pwm1 > 1200)) // if the stick / switch is in the middle (>1200<1800) blink slower
{
Serial.print(PWMInput1);
digitalWrite(LED1, HIGH);
delay(10);
digitalWrite(LED1, LOW); // blink slower while th pause is longer before the next "high" / blink is initiated
delay(500);
digitalWrite(LED1, HIGH);
delay(10);
digitalWrite(LED1, LOW); // wait 1second before it starts again
delay(1000);
}
else
{
Serial.print(PWMInput1);
}
}
// Feel free to modify it and share it with us.
// There will be over time different hardware stuff and
// 3D printed case linked / uploaded while I building several OpenLight for my Clubmates.
// Thanks for sharing and commenting if you need somehting and not able to do it on your own.
// List how you can support me:
// Patreon: https://www.patreon.com/dm4ds
// Paypal donation: https://www.paypal.com/paypalme/dm4ds
// BMAcoffee: https://buymeacoff.ee/dm4ds
// Bitcoin: bc1qf426e46h6kdtmws4cjnu6wa3wtzy8qvctq9j9u
// Etherium: 0x3447f956194706eCDab747314CFB92Bf55428F28
// List how / where you find me:
// Youtube: https://www.youtube.com/c/DM4DS
// Printables: https://www.printables.com/de/social/461183-dm4ds/about
// Twitter: https://twitter.com/HAM_DM4DS
// Instagram: https://www.instagram.com/dm4ds/
// Thingiverse: https://www.thingiverse.com/dm4ds/
// Thangs: https://thangs.com/DM4DS
// QRZ.com: https://www.qrz.com/lookup/DM4DS
// Twitch: https://www.twitch.tv/dm4ds
// Discord Server: https://discord.gg/xSzfBCyXCZ
// List of affiliate Shops / companies:
// Amazon Affiliate Link: https://amzn.to/31TI1FC
// CopterUni: https://kurs.copteruni.de/?ref=3a0ca5
// E-post adress:
// Email: info@dm4ds.de / dm4ds@gmx.de