-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathquinn_analog_in.device.nut
127 lines (107 loc) · 4.02 KB
/
quinn_analog_in.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// 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)
/* 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
*/
/* Note: Green and Blue are switched on the LED strips we purchased
* blue and green have therefore been switched below:
* Pin 2 = Green 1
* Pin 5 = Green 2
* Pin 8 = Blue 1
* Pin 9 = Blue 2
*/
// 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
{
type = "float"
redPin = null
grnPin = null
bluPin = null
constructor(name, redPin, grnPin, bluPin) {
base.constructor(name)
this.redPin = redPin
this.grnPin = grnPin
this.bluPin = bluPin
}
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 the values out to the pins
this.redPin.write(red);
this.grnPin.write(green);
this.bluPin.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");
local ch1 = rgbInput("Channel 1", hardware.pin1, hardware.pin2, hardware.pin9);
local ch2 = rgbInput("Channel 2", hardware.pin7, hardware.pin5, hardware.pin8);
imp.configure("Quinn", [ch1, ch2, switchInput() ], []);
//EOF