2 * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3 * Copyright (c) 2014 Intel Corporation.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait);
33 upm::LPD8806 *sensor = NULL;
36 sig_handler(int signo)
38 printf("got signal\n");
39 if (signo == SIGINT) {
40 printf("exiting application\n");
46 main(int argc, char **argv)
49 sensor = new upm::LPD8806(10, 7);
55 // Back-and-forth lights
56 scanner(127, 0, 0, 30); // red, slow
57 scanner(0, 0, 127, 15); // blue, fast
62 std::cout << "exiting application" << std::endl;
69 void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait) {
75 for(i=0; i < ((sensor->getStripLength() - 1) * 8); i++) {
76 // Draw 5 pixels centered on pos. setPixelColor() will clip
77 // any pixels off the ends of the strip, no worries there.
78 // we'll make the colors dimmer at the edges for a nice pulse
80 sensor->setPixelColor(pos - 2, r/4, g/4, b/4);
81 sensor->setPixelColor(pos - 1, r/2, g/2, b/2);
82 sensor->setPixelColor(pos, r, g, b);
83 sensor->setPixelColor(pos + 1, r/2, g/2, b/2);
84 sensor->setPixelColor(pos + 2, r/4, g/4, b/4);
88 // If we wanted to be sneaky we could erase just the tail end
89 // pixel, but it's much easier just to erase the whole thing
90 // and draw a new one next time.
91 for(j=-2; j<= 2; j++) {
92 sensor->setPixelColor(pos+j, 0,0,0);
94 // Bounce off ends of strip
99 } else if (pos >= sensor->getStripLength()) {
100 pos = sensor->getStripLength() - 2;