Code fonctionnel pour le chenillard de led du phare GE1
Dependencies: mbed LedStripGradient PololuLedStrip
Diff: main.cpp
- Revision:
- 10:557ad654e667
- Parent:
- 9:b1c530cad69b
- Child:
- 11:90f1a46b3724
--- a/main.cpp Tue Feb 26 23:23:02 2013 +0000 +++ b/main.cpp Wed Feb 27 02:48:05 2013 +0000 @@ -1,84 +1,29 @@ -#include "mbed.h" - -namespace Pololu -{ - #ifndef _POLOLU_RGB_COLOR - #define _POLOLU_RGB_COLOR - typedef struct rgb_color - { - uint8_t red, green, blue; - } rgb_color; - #endif - - extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask); - - class PololuLedStrip - { - static bool interruptFriendly; - public: - gpio_t gpio; - PololuLedStrip(PinName pin); - void write(rgb_color * colors, unsigned int count); - }; - - bool PololuLedStrip::interruptFriendly; - - PololuLedStrip::PololuLedStrip(PinName pinName) - { - gpio_init(&gpio, pinName, PIN_OUTPUT); - } - - void PololuLedStrip::write(rgb_color * colors, unsigned int count) - { - __disable_irq(); // Disable interrupts temporarily because we don't want our pulse timing to be messed up. - - while(count--) - { - led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask); - - if (interruptFriendly) - { - __enable_irq(); - __nop(); - __nop(); - __nop(); - __disable_irq(); - } - } - __enable_irq(); // Re-enable interrupts now that we are done. - wait_us(24); // Hold the line low for 24 microseconds to send the reset signal. - } -} - -using namespace Pololu; - -#define LED_COUNT 60 -rgb_color colors[LED_COUNT]; - -PololuLedStrip ledStrip(p8); - -DigitalOut led2(LED2); - -Timer timer; -AnalogOut signal(p18); - -int main() -{ - timer.start(); - - while(1) - { - uint8_t time = timer.read_ms() >> 2; - signal.write_u16(time << 8); - - for(uint8_t i = 0; i < LED_COUNT; i++) - { - uint8_t x = time - 8*i; - colors[i] = (rgb_color){ x, 255 - x, x }; - } - - led2 = !led2.read(); - ledStrip.write(colors, LED_COUNT); - wait_ms(10); - } -} +#include "mbed.h" +#include "PololuLedStrip.h" + +PololuLedStrip ledStrip(p8); + +#define LED_COUNT 60 +rgb_color colors[LED_COUNT]; + +Timer timer; + +int main() +{ + timer.start(); + + while(1) + { + // Update the colors array. + uint8_t time = timer.read_ms() >> 2; + for(int i = 0; i < LED_COUNT; i++) + { + uint8_t x = time - 8*i; + colors[i] = (rgb_color){ x, 255 - x, x }; + } + + // Send the colors to the LED strip. + ledStrip.write(colors, LED_COUNT); + wait_ms(10); + } +}