A hello world for inertial sensors

Dependencies:   FXAS21000 FXOS8700Q mbed

Fork of FRDM-STBC-AGM01 by angus taggart

Committer:
Elecia
Date:
Tue Jun 30 16:23:32 2015 +0000
Revision:
4:5ab2bb2f062b
Parent:
3:123b546e4a5c
Added element14 link

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Elecia 3:123b546e4a5c 1 // Smart LED handling
Elecia 3:123b546e4a5c 2
Elecia 3:123b546e4a5c 3 #include "led.h"
Elecia 3:123b546e4a5c 4
Elecia 3:123b546e4a5c 5 SMART_LED::SMART_LED(PinName redPin, PinName greenPin, PinName bluePin):
Elecia 3:123b546e4a5c 6 _redLedPwm(redPin), _greenLedPwm(greenPin), _blueLedPwm(bluePin)
Elecia 3:123b546e4a5c 7 {
Elecia 3:123b546e4a5c 8 _pwmLed[RED] = &_redLedPwm;
Elecia 3:123b546e4a5c 9 _pwmLed[GREEN] = &_greenLedPwm;
Elecia 3:123b546e4a5c 10 _pwmLed[BLUE] = &_blueLedPwm;
Elecia 3:123b546e4a5c 11 for (int i = 0; i < NUM_LEDS; i++) {
Elecia 3:123b546e4a5c 12 *_pwmLed[i] = 0;
Elecia 3:123b546e4a5c 13 _pwmLed[i]->period(0.001f);
Elecia 3:123b546e4a5c 14 _current[i] = 0;
Elecia 3:123b546e4a5c 15 _goal[i] = 0;
Elecia 3:123b546e4a5c 16 }
Elecia 3:123b546e4a5c 17 off();
Elecia 3:123b546e4a5c 18 }
Elecia 3:123b546e4a5c 19 void SMART_LED::ledUpdateTimerTick() {
Elecia 3:123b546e4a5c 20 for (int i = 0; i < NUM_LEDS; i++) {
Elecia 3:123b546e4a5c 21 if (_current[i] != _goal[i]) {
Elecia 3:123b546e4a5c 22 float newSetting = _goal[i];
Elecia 3:123b546e4a5c 23 if (newSetting < 0.0) { newSetting = 0.0;}
Elecia 3:123b546e4a5c 24 if (newSetting > 1.0) { newSetting = 1.0;}
Elecia 3:123b546e4a5c 25
Elecia 3:123b546e4a5c 26 *_pwmLed[i] = newSetting;
Elecia 3:123b546e4a5c 27 _current[i] = newSetting;
Elecia 3:123b546e4a5c 28 }
Elecia 3:123b546e4a5c 29 }
Elecia 3:123b546e4a5c 30 }
Elecia 3:123b546e4a5c 31 void SMART_LED::fadeToRgb(uint8_t r, uint8_t g, uint8_t b)
Elecia 3:123b546e4a5c 32 {
Elecia 3:123b546e4a5c 33 // not all LED colors are the same power,
Elecia 3:123b546e4a5c 34 // these empircially determined changes helps get them to be about the same
Elecia 3:123b546e4a5c 35 _goal[RED] = (200-r) / 150.0;
Elecia 3:123b546e4a5c 36 _goal[GREEN] = (255-g) / 225.0;
Elecia 3:123b546e4a5c 37 _goal[BLUE] = (300-b) / 255.0;
Elecia 3:123b546e4a5c 38 ledUpdateTimerTick();
Elecia 3:123b546e4a5c 39 }
Elecia 3:123b546e4a5c 40
Elecia 3:123b546e4a5c 41 void SMART_LED::off()
Elecia 3:123b546e4a5c 42 {
Elecia 3:123b546e4a5c 43 fadeToRgb(0,0,0);
Elecia 3:123b546e4a5c 44 }
Elecia 3:123b546e4a5c 45
Elecia 3:123b546e4a5c 46 void SMART_LED::set(uint8_t r, uint8_t g, uint8_t b)
Elecia 3:123b546e4a5c 47 {
Elecia 3:123b546e4a5c 48 fadeToRgb(r, g, b);
Elecia 3:123b546e4a5c 49 }