library for m3Dpi robot, based on the Pololu 3pi and m3pi. m3Dpi has multiple distance sensors, gyroscope, compass and accelerometer sensor to be fully aware of its environment. With the addition of xbee or nrf24n01 module it has wireless communication capabilities.

Dependencies:   m3pi ADXL345_I2C HMC5583L ITG3200 PCA9547 TLC59116 VL6180x RGB-fun xbee

Dependents:   m3Dpi-helloworld

Committer:
sillevl
Date:
Thu Dec 03 07:58:50 2015 +0000
Revision:
0:9f02ae958e20
Child:
10:4200a8140b10
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sillevl 0:9f02ae958e20 1 #include "LedRing.h"
sillevl 0:9f02ae958e20 2
sillevl 0:9f02ae958e20 3
sillevl 0:9f02ae958e20 4 LedRing::LedRing(PinName sda, PinName scl): driver1(sda, scl, DRIVER_1_ADDRESS), driver2(sda, scl, DRIVER_2_ADDRESS)
sillevl 0:9f02ae958e20 5 {
sillevl 0:9f02ae958e20 6 driver1.enable();
sillevl 0:9f02ae958e20 7 driver2.enable();
sillevl 0:9f02ae958e20 8
sillevl 0:9f02ae958e20 9 setBrightness(0.05);
sillevl 0:9f02ae958e20 10 }
sillevl 0:9f02ae958e20 11
sillevl 0:9f02ae958e20 12 void LedRing::setColor(int led, Color* color)
sillevl 0:9f02ae958e20 13 {
sillevl 0:9f02ae958e20 14 led--; // zero indexed from now on
sillevl 0:9f02ae958e20 15 led = led % 8;
sillevl 0:9f02ae958e20 16
sillevl 0:9f02ae958e20 17 int channelMap[8] = {0, 3, 6, 0, 3, 6, 9, 9};
sillevl 0:9f02ae958e20 18 int driverMap[8] = {1, 1, 1, 2, 2, 2, 2, 1};
sillevl 0:9f02ae958e20 19
sillevl 0:9f02ae958e20 20 TLC59116* driver = (driverMap[led] == 1) ? &driver1 : &driver2;
sillevl 0:9f02ae958e20 21 int startChannel = channelMap[led];
sillevl 0:9f02ae958e20 22
sillevl 0:9f02ae958e20 23 setLed(driver, startChannel, color);
sillevl 0:9f02ae958e20 24 }
sillevl 0:9f02ae958e20 25
sillevl 0:9f02ae958e20 26 void LedRing::setColor(int led, int color)
sillevl 0:9f02ae958e20 27 {
sillevl 0:9f02ae958e20 28 Color* _color = new Color(color);
sillevl 0:9f02ae958e20 29 setColor(led, _color);
sillevl 0:9f02ae958e20 30 delete _color;
sillevl 0:9f02ae958e20 31 }
sillevl 0:9f02ae958e20 32
sillevl 0:9f02ae958e20 33 void LedRing::setAll(Color* color)
sillevl 0:9f02ae958e20 34 {
sillevl 0:9f02ae958e20 35 for(int i = 0; i < 8; i++){
sillevl 0:9f02ae958e20 36 setColor(i+1, color);
sillevl 0:9f02ae958e20 37 }
sillevl 0:9f02ae958e20 38 }
sillevl 0:9f02ae958e20 39
sillevl 0:9f02ae958e20 40 void LedRing::setAll(int color)
sillevl 0:9f02ae958e20 41 {
sillevl 0:9f02ae958e20 42 Color* _color = new Color(color);
sillevl 0:9f02ae958e20 43 setAll(_color);
sillevl 0:9f02ae958e20 44 delete _color;
sillevl 0:9f02ae958e20 45 }
sillevl 0:9f02ae958e20 46
sillevl 0:9f02ae958e20 47 void LedRing::setAll(int* colors)
sillevl 0:9f02ae958e20 48 {
sillevl 0:9f02ae958e20 49 for(int i = 0; i < 8; i++){
sillevl 0:9f02ae958e20 50 setColor(i+1, colors[i]);
sillevl 0:9f02ae958e20 51 }
sillevl 0:9f02ae958e20 52 }
sillevl 0:9f02ae958e20 53
sillevl 0:9f02ae958e20 54 void LedRing::setLed(TLC59116* driver, int startChannel, Color* color)
sillevl 0:9f02ae958e20 55 {
sillevl 0:9f02ae958e20 56 driver->setChannel(startChannel + 0, color->getRed() / 255.0);
sillevl 0:9f02ae958e20 57 driver->setChannel(startChannel + 1, color->getGreen() / 255.0);
sillevl 0:9f02ae958e20 58 driver->setChannel(startChannel + 2, color->getBlue() / 255.0);
sillevl 0:9f02ae958e20 59 }
sillevl 0:9f02ae958e20 60
sillevl 0:9f02ae958e20 61 void LedRing::setBrightness(float brightness)
sillevl 0:9f02ae958e20 62 {
sillevl 0:9f02ae958e20 63 driver1.setBrightness(brightness);
sillevl 0:9f02ae958e20 64 driver2.setBrightness(brightness);
sillevl 0:9f02ae958e20 65 }
sillevl 0:9f02ae958e20 66
sillevl 0:9f02ae958e20 67 void LedRing::greenRedGradient(int led, int value)
sillevl 0:9f02ae958e20 68 {
sillevl 0:9f02ae958e20 69 Color* _color = new Color(255 - value, value, 0);
sillevl 0:9f02ae958e20 70 setColor(led, _color);
sillevl 0:9f02ae958e20 71 delete _color;
sillevl 0:9f02ae958e20 72 }