Code for controlling mbed hardware (LED's, motors), as well as code for the Raspberry Pi to run a Support Vector Machine that identifies objects using the Pi camera

Dependencies:   mbed Motordriver mbed-rtos PololuLedStrip

Committer:
arogliero3
Date:
Thu Dec 05 20:34:10 2019 -0500
Revision:
0:e0dbd261724a
Adding code to mbed repo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
arogliero3 0:e0dbd261724a 1 #include "mbed.h"
arogliero3 0:e0dbd261724a 2
arogliero3 0:e0dbd261724a 3 #ifndef _POLOLU_LED_STRIP_H
arogliero3 0:e0dbd261724a 4 #define _POLOLU_LED_STRIP_H
arogliero3 0:e0dbd261724a 5
arogliero3 0:e0dbd261724a 6 namespace Pololu
arogliero3 0:e0dbd261724a 7 {
arogliero3 0:e0dbd261724a 8 #ifndef _POLOLU_RGB_COLOR
arogliero3 0:e0dbd261724a 9 #define _POLOLU_RGB_COLOR
arogliero3 0:e0dbd261724a 10
arogliero3 0:e0dbd261724a 11 /** Represents an RGB color. */
arogliero3 0:e0dbd261724a 12 typedef struct rgb_color
arogliero3 0:e0dbd261724a 13 {
arogliero3 0:e0dbd261724a 14 uint8_t red; /*!< A number between 0 and 255 that represents the brightness of the red component. */
arogliero3 0:e0dbd261724a 15 uint8_t green; /*!< A number between 0 and 255 that represents the brightness of the green component. */
arogliero3 0:e0dbd261724a 16 uint8_t blue; /*!< A number between 0 and 255 that represents the brightness of the blue component. */
arogliero3 0:e0dbd261724a 17 } rgb_color;
arogliero3 0:e0dbd261724a 18 #endif
arogliero3 0:e0dbd261724a 19
arogliero3 0:e0dbd261724a 20 extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask);
arogliero3 0:e0dbd261724a 21
arogliero3 0:e0dbd261724a 22 /** This class lets you control the addressable RGB LED strips from Pololu</a>,
arogliero3 0:e0dbd261724a 23 or any other LED strip based on the TM1804 chip. */
arogliero3 0:e0dbd261724a 24 class PololuLedStrip
arogliero3 0:e0dbd261724a 25 {
arogliero3 0:e0dbd261724a 26 gpio_t gpio;
arogliero3 0:e0dbd261724a 27
arogliero3 0:e0dbd261724a 28 public:
arogliero3 0:e0dbd261724a 29
arogliero3 0:e0dbd261724a 30 /** This constructor lets you make an led strip object by specifying the pin name.
arogliero3 0:e0dbd261724a 31 There are no restrictions on what pin you can choose.
arogliero3 0:e0dbd261724a 32
arogliero3 0:e0dbd261724a 33 Example:
arogliero3 0:e0dbd261724a 34 @code
arogliero3 0:e0dbd261724a 35 PololuLedStrip ledStrip(p8);
arogliero3 0:e0dbd261724a 36 @endcode
arogliero3 0:e0dbd261724a 37 */
arogliero3 0:e0dbd261724a 38 PololuLedStrip(PinName pin);
arogliero3 0:e0dbd261724a 39
arogliero3 0:e0dbd261724a 40 /** Writes the specified series of colors to the LED strip.
arogliero3 0:e0dbd261724a 41 @param colors should be a pointer to an array of rgb_color structs.
arogliero3 0:e0dbd261724a 42 @param count should be the number of colors to write.
arogliero3 0:e0dbd261724a 43
arogliero3 0:e0dbd261724a 44 The first color in the array will be written to the LED closest to the data input connector.
arogliero3 0:e0dbd261724a 45 To update all the LEDs in the LED strip, count should be equal to or greater than the number of LEDs in the strip.
arogliero3 0:e0dbd261724a 46 If count is less than the number of LEDs in the strip, then some LEDs near the end of the strip will not be updated.
arogliero3 0:e0dbd261724a 47
arogliero3 0:e0dbd261724a 48 The colors are sent in series and each color takes about 45 microseconds to send.
arogliero3 0:e0dbd261724a 49 This function disables interrupts temporarily while it is running.
arogliero3 0:e0dbd261724a 50 This function waits for over 10 us at the end before returning to allow the colors to take effect.
arogliero3 0:e0dbd261724a 51 */
arogliero3 0:e0dbd261724a 52 void write(rgb_color * colors, unsigned int count);
arogliero3 0:e0dbd261724a 53
arogliero3 0:e0dbd261724a 54 /** This option defaults to <code>false</code>.
arogliero3 0:e0dbd261724a 55 Setting this to true changes the behavior of the write function, making it enable interrupts
arogliero3 0:e0dbd261724a 56 after each color is sent, about every 60 microseconds.
arogliero3 0:e0dbd261724a 57 This allows your program to respond to interrupts faster, but makes it possible for an interrupt
arogliero3 0:e0dbd261724a 58 that takes longer than 8 microseconds to screw up the transmission of colors to the LED strip.
arogliero3 0:e0dbd261724a 59
arogliero3 0:e0dbd261724a 60 Example:
arogliero3 0:e0dbd261724a 61 @code
arogliero3 0:e0dbd261724a 62 PololuLedStrip::interruptFriendly = true;
arogliero3 0:e0dbd261724a 63 @endcode
arogliero3 0:e0dbd261724a 64 */
arogliero3 0:e0dbd261724a 65 static bool interruptFriendly;
arogliero3 0:e0dbd261724a 66
arogliero3 0:e0dbd261724a 67 static void calculateDelays();
arogliero3 0:e0dbd261724a 68 };
arogliero3 0:e0dbd261724a 69 }
arogliero3 0:e0dbd261724a 70
arogliero3 0:e0dbd261724a 71 using namespace Pololu;
arogliero3 0:e0dbd261724a 72
arogliero3 0:e0dbd261724a 73 #endif