school project using led strip
Fork of PololuLedStrip by
PololuLedStrip.cpp
- Committer:
- DavidEGrayson
- Date:
- 2013-03-01
- Revision:
- 10:f1bb84b97788
- Parent:
- 9:6ffb85d69eaf
- Child:
- 12:b6df8ac053c8
File content as of revision 10:f1bb84b97788:
#include "PololuLedStrip.h" bool PololuLedStrip::interruptFriendly = false; uint8_t led_strip_write_delays[3]; void PololuLedStrip::calculateDelays() { // Get the clock frequency in MHz. int f_mhz = SystemCoreClock / 1000000; // Arrange for a 700 nanosecond delay between the rise time and the fall time for a 0 bit. led_strip_write_delays[0] = 700*f_mhz/1000 - 32; // Arrange for a 600 nanosecond delay between the fall time for a 0 bit and the fall time for a 1 bit. // This means the pulses representing a 1 will be 700+600 = 1300 nanoseconds. led_strip_write_delays[1] = 600*f_mhz/1000 - 19; // Arrange for a 1200 nanosecond delay between the fall time for a 1 bit and rise time of the next bit. // This means the period of the signal will be 2500 nanoseconds. led_strip_write_delays[2] = 1200*f_mhz/1000 - 24; led_strip_write_delays[0] <<= 1; led_strip_write_delays[1] <<= 1; led_strip_write_delays[2] <<= 1; } PololuLedStrip::PololuLedStrip(PinName pinName) { gpio_init(&gpio, pinName, PIN_OUTPUT); } void PololuLedStrip::write(rgb_color * colors, unsigned int count) { calculateDelays(); __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); colors++; 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. //*(gpio.reg_set) = gpio.mask; //*(gpio.reg_clr) = gpio.mask; }