-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlightbar.html
87 lines (85 loc) · 3.79 KB
/
lightbar.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>electrosite</title>
<link rel="stylesheet" href="style.css">
<!-- <script src="script.js"></script> -->
</head>
<body>
<header>
<a href="index.html"><img src="img\arrowed.gif"></a>
</header>
<h2>Light Bar</h2>
<img src="lightbar\policenight.gif">
<p>Used scavanged parts from an old printer/scanner, a lithium cell from an used battery and an Attiny to make a light bar, whatever that is.</p>
<hr>
<img src="lightbar/parts.jpg">
<p>Disassembling a multifunction printer yelds lots of components. They're a goldmine for parts. Got some motors, optical sensors, momentary switches, the scanner light which is used here and a laser module.</p>
<hr>
<img src="lightbar/circuit.jpg">
<p>After trying some current limited, low voltages on the pins of the scanner light bar, I realized it's a bunch of rgb leds with a common cathode. The circuit is very simple, driving the leds directly from 3 pins of the Attiny, though some resistors. A fourth pin is used with the linear potentiometer as an input.</p>
<hr>
<img src="lightbar/battery.jpg">
<p>This will be powered by a lithium cell I got from a 4 cell battery (2 cells visible here).</p>
<hr>
<img src="lightbar/chip1.jpg"><!--<img src="lightbar/chip2.jpg">-->
<p>I used this module to take care of the charging/discharging process. Very inexpensive. However, its output is a USB type A. Had to remove the female plug and wire it directly.</p>
<hr>
<img src="lightbar/assem2.jpg">
<p>The switch, potentiometer, resistors and the chip socket were mounter to some perf board.</p>
<hr>
<img src="lightbar/final1.jpg">
<p>The end result is pretty crusty but it works. The Attiny code cycles through the rainbow as the potentiometer moves. If the potentiometer is at one end it will blink police lights. And at the other end it will slowly 'breathe' white.</p>
<p>As the strip has 4 wires, one for each color and a common cathode, it takes RGB values. I wanted to cycle through all the color hues linearly with the potentiometer. This meant I had to convert colors from HSV to RGB. The math for that wasn't straightforward so I usurped it.</p>
<pre>
<code>
void setLedColorHSV(byte h, byte s, byte v) {
h = (h * 192) / 256; // 0..191
unsigned int i = h / 32; // We want a value of 0 thru 5
unsigned int f = (h % 32) * 8; // 'fractional' part of 'i' 0..248 in jumps
unsigned int sInv = 255 - s; // 0 -> 0xff, 0xff -> 0
unsigned int fInv = 255 - f; // 0 -> 0xff, 0xff -> 0
byte pv = v * sInv / 256; // pv will be in range 0 - 255
byte qv = v * (256 - s * f / 256) / 256;
byte tv = v * (256 - s * fInv / 256) / 256;
switch (i) {
case 0:
RedLight = v;
GreenLight = tv;
BlueLight = pv;
break;
case 1:
RedLight = qv;
GreenLight = v;
BlueLight = pv;
break;
case 2:
RedLight = pv;
GreenLight = v;
BlueLight = tv;
break;
case 3:
RedLight = pv;
GreenLight = qv;
BlueLight = v;
break;
case 4:
RedLight = tv;
GreenLight = pv;
BlueLight = v;
break;
case 5:
RedLight = v;
GreenLight = pv;
BlueLight = qv;
break;
}
}
</code>
</pre>
<p>The solar panels are rated for 0.5V. Two output a max of 1V under full sun, usualy less than that. The joule thief boosts it enough to light up the LEDs.</p>
<hr>
<img src="lightbar/final2.jpg">
</body>
</html>