changed this somehow

Fork of NeoStrip by Allen Wild

Committer:
rhodes42
Date:
Fri Apr 25 14:39:19 2014 +0000
Revision:
1:cf7e969704ec
Parent:
0:9f237b11f0a8
updated gpio_init to gpio_init_out;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aswild 0:9f237b11f0a8 1 /**
aswild 0:9f237b11f0a8 2 * NeoStrip.h
aswild 0:9f237b11f0a8 3 *
aswild 0:9f237b11f0a8 4 * Allen Wild
aswild 0:9f237b11f0a8 5 * March 2014
aswild 0:9f237b11f0a8 6 *
aswild 0:9f237b11f0a8 7 * Library for the control of Adafruit NeoPixel addressable RGB LEDs.
aswild 0:9f237b11f0a8 8 */
aswild 0:9f237b11f0a8 9
rhodes42 1:cf7e969704ec 10 #include "mbed.h"
rhodes42 1:cf7e969704ec 11 #include <stdint.h>
rhodes42 1:cf7e969704ec 12
aswild 0:9f237b11f0a8 13
aswild 0:9f237b11f0a8 14 #ifndef NEOSTRIP_H
aswild 0:9f237b11f0a8 15 #define NEOSTRIP_H
aswild 0:9f237b11f0a8 16
aswild 0:9f237b11f0a8 17 #ifndef TARGET_LPC1768
aswild 0:9f237b11f0a8 18 #error NeoStrip only supports the NXP LPC1768!
aswild 0:9f237b11f0a8 19 #endif
aswild 0:9f237b11f0a8 20
aswild 0:9f237b11f0a8 21 // NeoColor struct definition to hold 24 bit
aswild 0:9f237b11f0a8 22 // color data for each pixel, in GRB order
aswild 0:9f237b11f0a8 23 typedef struct _NeoColor
aswild 0:9f237b11f0a8 24 {
aswild 0:9f237b11f0a8 25 uint8_t green;
aswild 0:9f237b11f0a8 26 uint8_t red;
aswild 0:9f237b11f0a8 27 uint8_t blue;
aswild 0:9f237b11f0a8 28 } NeoColor;
aswild 0:9f237b11f0a8 29
aswild 0:9f237b11f0a8 30 /**
aswild 0:9f237b11f0a8 31 * NeoStrip objects manage the buffering and assigning of
aswild 0:9f237b11f0a8 32 * addressable NeoPixels
aswild 0:9f237b11f0a8 33 */
aswild 0:9f237b11f0a8 34 class NeoStrip
aswild 0:9f237b11f0a8 35 {
aswild 0:9f237b11f0a8 36 public:
aswild 0:9f237b11f0a8 37
aswild 0:9f237b11f0a8 38 /**
aswild 0:9f237b11f0a8 39 * Create a NeoStrip object
aswild 0:9f237b11f0a8 40 *
aswild 0:9f237b11f0a8 41 * @param pin The mbed data pin name
aswild 0:9f237b11f0a8 42 * @param N The number of pixels in the strip
aswild 0:9f237b11f0a8 43 */
aswild 0:9f237b11f0a8 44 NeoStrip(PinName pin, int N);
aswild 0:9f237b11f0a8 45
aswild 0:9f237b11f0a8 46 /**
aswild 0:9f237b11f0a8 47 * Set an overall brightness scale for the entire strip.
aswild 0:9f237b11f0a8 48 * When colors are set using setPixel(), they are scaled
aswild 0:9f237b11f0a8 49 * according to this brightness.
aswild 0:9f237b11f0a8 50 *
aswild 0:9f237b11f0a8 51 * Because NeoPixels are very bright and draw a lot of current,
aswild 0:9f237b11f0a8 52 * the brightness is set to 0.5 by default.
aswild 0:9f237b11f0a8 53 *
aswild 0:9f237b11f0a8 54 * @param bright The brightness scale between 0 and 1.0
aswild 0:9f237b11f0a8 55 */
aswild 0:9f237b11f0a8 56 void setBrightness(float bright);
aswild 0:9f237b11f0a8 57
aswild 0:9f237b11f0a8 58 /**
aswild 0:9f237b11f0a8 59 * Set a single pixel to the specified color.
aswild 0:9f237b11f0a8 60 *
aswild 0:9f237b11f0a8 61 * This method (and all other setPixel methods) uses modulo-N arithmetic
aswild 0:9f237b11f0a8 62 * when addressing pixels. If p >= N, the pixel address will wrap around.
aswild 0:9f237b11f0a8 63 *
aswild 0:9f237b11f0a8 64 * @param p The pixel number (starting at 0) to set
aswild 0:9f237b11f0a8 65 * @param color A 24-bit color packed into a single int,
aswild 0:9f237b11f0a8 66 * using standard hex color codes (e.g. 0xFF0000 is red)
aswild 0:9f237b11f0a8 67 */
aswild 0:9f237b11f0a8 68 void setPixel(int p, int color);
aswild 0:9f237b11f0a8 69
aswild 0:9f237b11f0a8 70 /**
aswild 0:9f237b11f0a8 71 * Set a single pixel to the specified color, with red, green, and blue
aswild 0:9f237b11f0a8 72 * values in separate arguments.
aswild 0:9f237b11f0a8 73 */
aswild 0:9f237b11f0a8 74 void setPixel(int p, uint8_t red, uint8_t green, uint8_t blue);
rhodes42 1:cf7e969704ec 75
rhodes42 1:cf7e969704ec 76 /**
rhodes42 1:cf7e969704ec 77 * Multiply a pixel value by mask so that you can turn colored pixels on/off
rhodes42 1:cf7e969704ec 78 * for displaying text
rhodes42 1:cf7e969704ec 79 */
rhodes42 1:cf7e969704ec 80
aswild 0:9f237b11f0a8 81
aswild 0:9f237b11f0a8 82 /**
aswild 0:9f237b11f0a8 83 * Set n pixels starting at pixel p.
aswild 0:9f237b11f0a8 84 *
aswild 0:9f237b11f0a8 85 * @param p The first pixel in the strip to set.
aswild 0:9f237b11f0a8 86 * @param n The number of pixels to set.
aswild 0:9f237b11f0a8 87 * @param colors An array of length n containing the 24-bit colors for each pixel
aswild 0:9f237b11f0a8 88 */
aswild 0:9f237b11f0a8 89 void setPixels(int p, int n, const int *colors);
aswild 0:9f237b11f0a8 90
aswild 0:9f237b11f0a8 91 /**
aswild 0:9f237b11f0a8 92 * Reset all pixels in the strip to be of (0x000000)
aswild 0:9f237b11f0a8 93 */
aswild 0:9f237b11f0a8 94 void clear();
aswild 0:9f237b11f0a8 95
aswild 0:9f237b11f0a8 96 /**
aswild 0:9f237b11f0a8 97 * Write the colors out to the strip; this method must be called
aswild 0:9f237b11f0a8 98 * to see any hardware effect.
aswild 0:9f237b11f0a8 99 *
aswild 0:9f237b11f0a8 100 * This function disables interrupts while the strip data is being sent,
aswild 0:9f237b11f0a8 101 * each pixel takes approximately 30us to send, plus a 50us reset pulse
aswild 0:9f237b11f0a8 102 * at the end.
aswild 0:9f237b11f0a8 103 */
aswild 0:9f237b11f0a8 104 void write();
rhodes42 1:cf7e969704ec 105
rhodes42 1:cf7e969704ec 106
rhodes42 1:cf7e969704ec 107
aswild 0:9f237b11f0a8 108
aswild 0:9f237b11f0a8 109 protected:
aswild 0:9f237b11f0a8 110 NeoColor *strip; // pixel data buffer modified by setPixel() and used by neo_out()
aswild 0:9f237b11f0a8 111 int N; // the number of pixels in the strip
aswild 0:9f237b11f0a8 112 int Nbytes; // the number of bytes of pixel data (always N*3)
aswild 0:9f237b11f0a8 113 float bright; // the master strip brightness
aswild 0:9f237b11f0a8 114 gpio_t gpio; // gpio struct for initialization and getting register addresses
aswild 0:9f237b11f0a8 115 };
aswild 0:9f237b11f0a8 116
aswild 0:9f237b11f0a8 117 #endif
aswild 0:9f237b11f0a8 118
aswild 0:9f237b11f0a8 119