Example code for using the RedNearNano_NeoPixels library

Dependencies:   RedBearNano_NeoPixels

Committer:
bickster
Date:
Thu Jul 09 02:08:35 2015 +0000
Revision:
0:a3770f1be412
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bickster 0:a3770f1be412 1 /* Copyright (c) 2015 bickster, MIT License
bickster 0:a3770f1be412 2 *
bickster 0:a3770f1be412 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
bickster 0:a3770f1be412 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
bickster 0:a3770f1be412 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
bickster 0:a3770f1be412 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
bickster 0:a3770f1be412 7 * furnished to do so, subject to the following conditions:
bickster 0:a3770f1be412 8 *
bickster 0:a3770f1be412 9 * The above copyright notice and this permission notice shall be included in all copies or
bickster 0:a3770f1be412 10 * substantial portions of the Software.
bickster 0:a3770f1be412 11 *
bickster 0:a3770f1be412 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
bickster 0:a3770f1be412 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bickster 0:a3770f1be412 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
bickster 0:a3770f1be412 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bickster 0:a3770f1be412 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bickster 0:a3770f1be412 17 */
bickster 0:a3770f1be412 18 #include "mbed.h"
bickster 0:a3770f1be412 19 #include "neopixel.h"
bickster 0:a3770f1be412 20
bickster 0:a3770f1be412 21 int main(void)
bickster 0:a3770f1be412 22 {
bickster 0:a3770f1be412 23 neopixel_strip_t m_strip;
bickster 0:a3770f1be412 24 uint8_t dig_pin_num = P0_8;
bickster 0:a3770f1be412 25 uint8_t leds_per_strip = 4;
bickster 0:a3770f1be412 26 uint8_t error;
bickster 0:a3770f1be412 27 uint8_t led_to_enable = 1;
bickster 0:a3770f1be412 28 uint8_t red = 255;
bickster 0:a3770f1be412 29 uint8_t green = 0;
bickster 0:a3770f1be412 30 uint8_t blue = 159;
bickster 0:a3770f1be412 31
bickster 0:a3770f1be412 32 neopixel_init(&m_strip, dig_pin_num, leds_per_strip);
bickster 0:a3770f1be412 33 neopixel_clear(&m_strip);
bickster 0:a3770f1be412 34
bickster 0:a3770f1be412 35 // red=0;green=0;blue=0; turns off led
bickster 0:a3770f1be412 36 // To turn off all leds call neopixel_clear(&m_strip);
bickster 0:a3770f1be412 37
bickster 0:a3770f1be412 38 // To show more than one led call this funtion n number of times.
bickster 0:a3770f1be412 39 error = neopixel_set_color_and_show(&m_strip, led_to_enable, red, green, blue);
bickster 0:a3770f1be412 40 if (error) {
bickster 0:a3770f1be412 41 //led_to_enable was not within number leds_per_strip
bickster 0:a3770f1be412 42 }
bickster 0:a3770f1be412 43
bickster 0:a3770f1be412 44 while (1) {
bickster 0:a3770f1be412 45 wait(0.2);
bickster 0:a3770f1be412 46 }
bickster 0:a3770f1be412 47
bickster 0:a3770f1be412 48 }