-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathquinn_ceiling.device.nut
111 lines (93 loc) · 3.59 KB
/
quinn_ceiling.device.nut
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
// NOTE:
// This example uses Input/Output Ports, which have been replaced by Agents and HTTP request-based communication.
// This code will not work as currently written, but remains primarily as a reference for older designs.
// Examples of the current communication architecture are available at http://electricimp.com/docs/examples/
/*
Copyright (C) 2013 electric imp, inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// 6-channel 5A PWM Driver (Float 0.0 to 1.0 In) with Paired Channels
/* Pin Assignments according to silkscreen
* Pin 1 = Red 1
* Pin 2 = Blue 1
* Pin 5 = Blue 2
* Pin 7 = Red 2
* Pin 8 = Green 2
* Pin 9 = Green 1
*/
// initialize some handy values
// PWM frequency in Hz
local pwm_f = 500.0;
// Configure hardware
hardware.pin1.configure(PWM_OUT, 1.0/pwm_f, 256.0, 256);
hardware.pin2.configure(PWM_OUT, 1.0/pwm_f, 256.0, 256);
hardware.pin5.configure(PWM_OUT, 1.0/pwm_f, 256.0, 256);
hardware.pin7.configure(PWM_OUT, 1.0/pwm_f, 256.0, 256);
hardware.pin8.configure(PWM_OUT, 1.0/pwm_f, 256.0, 256);
hardware.pin9.configure(PWM_OUT, 1.0/pwm_f, 256.0, 256);
server.log("Hardware Configured");
class rgbInput extends InputPort
{
name = "Analog Input"
type = "float"
function set(value) {
// fully counterclockwise = red
local red = 255.0 - (510.0) * value;
if (red < 0.0) {
red = 0.0;
}
server.log(format("%s Red set to %.2f", name, red));
// 50% = green
local green = 0.0;
if (value < 0.5) {
green = 255.0 - (510.0 * (0.5 - value));
} else {
green = 255.0 - (510.0 * (value - 0.5));
}
server.log(format("%s Green set to %.2f", name, green));
// fully clockwise = blue
local blue = 0.0;
if (value <= 0.5) {
blue = 0.0;
} else {
blue = 510.0 * (value-0.5);
}
server.log(format("%s Blue set to %.2f,", name, blue));
// now write values to pins
hardware.pin1.write(red);
hardware.pin7.write(red);
hardware.pin9.write(green);
hardware.pin8.write(green);
hardware.pin2.write(blue);
hardware.pin5.write(blue);
}
}
class switchInput extends InputPort
{
name = "Switch Input"
type = "On/Off"
function set(value) {
if (value == 0) {
hardware.pin1.write(0.0);
hardware.pin2.write(0.0);
hardware.pin5.write(0.0);
hardware.pin7.write(0.0);
hardware.pin8.write(0.0);
hardware.pin9.write(0.0);
}
}
}
server.log("Quinn Started");
imp.configure("Quinn", [rgbInput(), switchInput() ], []);
//EOF