Balancimg MPU6050 by LEDs on PWM
It is possible to observe the MPU6050 data on serial. If serial termimal is not started then still LED application runs.
There are 4 LEDs on LPC1768. So the first 3 LEDs are assign to accelerometer X, Y and Z. The last LED can drive by user. Default it lights a bit. If you want to turn it off then change the value as "190" to "180" on this line: myled4 = cos(190*2.0*3.13/360) * 0.5 + 0.5; If you want to turn it on (full) then change the value as "190" to "0" on above code line.
I2Cdev.h@0:9a1aae56ed19, 2013-10-13 (annotated)
- Committer:
- LORDTEK
- Date:
- Sun Oct 13 12:01:33 2013 +0000
- Revision:
- 0:9a1aae56ed19
Balancing MPU6050 by LEDs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LORDTEK | 0:9a1aae56ed19 | 1 | //ported from arduino library: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050 |
LORDTEK | 0:9a1aae56ed19 | 2 | //written by szymon gaertig (email: szymon@gaertig.com.pl) |
LORDTEK | 0:9a1aae56ed19 | 3 | // |
LORDTEK | 0:9a1aae56ed19 | 4 | //Changelog: |
LORDTEK | 0:9a1aae56ed19 | 5 | //2013-01-08 - first beta release |
LORDTEK | 0:9a1aae56ed19 | 6 | |
LORDTEK | 0:9a1aae56ed19 | 7 | #ifndef I2Cdev_h |
LORDTEK | 0:9a1aae56ed19 | 8 | #define I2Cdev_h |
LORDTEK | 0:9a1aae56ed19 | 9 | |
LORDTEK | 0:9a1aae56ed19 | 10 | #include "mbed.h" |
LORDTEK | 0:9a1aae56ed19 | 11 | |
LORDTEK | 0:9a1aae56ed19 | 12 | #define I2C_SDA p28 |
LORDTEK | 0:9a1aae56ed19 | 13 | #define I2C_SCL p27 |
LORDTEK | 0:9a1aae56ed19 | 14 | |
LORDTEK | 0:9a1aae56ed19 | 15 | class I2Cdev { |
LORDTEK | 0:9a1aae56ed19 | 16 | private: |
LORDTEK | 0:9a1aae56ed19 | 17 | I2C i2c; |
LORDTEK | 0:9a1aae56ed19 | 18 | Serial debugSerial; |
LORDTEK | 0:9a1aae56ed19 | 19 | public: |
LORDTEK | 0:9a1aae56ed19 | 20 | I2Cdev(); |
LORDTEK | 0:9a1aae56ed19 | 21 | I2Cdev(PinName i2cSda, PinName i2cScl); |
LORDTEK | 0:9a1aae56ed19 | 22 | |
LORDTEK | 0:9a1aae56ed19 | 23 | int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
LORDTEK | 0:9a1aae56ed19 | 24 | int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
LORDTEK | 0:9a1aae56ed19 | 25 | int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
LORDTEK | 0:9a1aae56ed19 | 26 | int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
LORDTEK | 0:9a1aae56ed19 | 27 | int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
LORDTEK | 0:9a1aae56ed19 | 28 | int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
LORDTEK | 0:9a1aae56ed19 | 29 | int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
LORDTEK | 0:9a1aae56ed19 | 30 | int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
LORDTEK | 0:9a1aae56ed19 | 31 | |
LORDTEK | 0:9a1aae56ed19 | 32 | bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data); |
LORDTEK | 0:9a1aae56ed19 | 33 | bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data); |
LORDTEK | 0:9a1aae56ed19 | 34 | bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data); |
LORDTEK | 0:9a1aae56ed19 | 35 | bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data); |
LORDTEK | 0:9a1aae56ed19 | 36 | bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data); |
LORDTEK | 0:9a1aae56ed19 | 37 | bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data); |
LORDTEK | 0:9a1aae56ed19 | 38 | bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data); |
LORDTEK | 0:9a1aae56ed19 | 39 | bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data); |
LORDTEK | 0:9a1aae56ed19 | 40 | |
LORDTEK | 0:9a1aae56ed19 | 41 | static uint16_t readTimeout(void); |
LORDTEK | 0:9a1aae56ed19 | 42 | }; |
LORDTEK | 0:9a1aae56ed19 | 43 | |
LORDTEK | 0:9a1aae56ed19 | 44 | #endif |