Programme complet du projet SBra. Lecture de 64 capteur thermique I2C avec 2 multiplexeur TCA9548A, enregistrement sur carte microSD et communication BLE.
Dependencies: TCA9548A mbed SimpleBLE X_NUCLEO_IDB0XA1 SDFileSystem3 USBDevice
main.cpp@7:f5e10b18984d, 2019-12-17 (annotated)
- Committer:
- jimbaud
- Date:
- Tue Dec 17 14:23:20 2019 +0000
- Revision:
- 7:f5e10b18984d
- Parent:
- 6:1670244c4eb4
- Child:
- 9:0b803d9b4af4
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jimbaud | 6:1670244c4eb4 | 1 | //Includes |
jimbaud | 6:1670244c4eb4 | 2 | |
janjongboom | 0:ba1c49874d3c | 3 | #include "mbed.h" |
janjongboom | 0:ba1c49874d3c | 4 | #include "SimpleBLE.h" |
jimbaud | 6:1670244c4eb4 | 5 | #include "LIS3DH.h" |
janjongboom | 0:ba1c49874d3c | 6 | |
jimbaud | 6:1670244c4eb4 | 7 | //Accelerometer |
jimbaud | 6:1670244c4eb4 | 8 | |
jimbaud | 6:1670244c4eb4 | 9 | #define MOSI PC_12 |
jimbaud | 6:1670244c4eb4 | 10 | #define MISO PC_11 |
jimbaud | 6:1670244c4eb4 | 11 | #define CS PC_5 |
jimbaud | 6:1670244c4eb4 | 12 | #define SCLK PC_10 |
jimbaud | 6:1670244c4eb4 | 13 | |
jimbaud | 6:1670244c4eb4 | 14 | //Init simpleBLE |
jimbaud | 6:1670244c4eb4 | 15 | |
jimbaud | 7:f5e10b18984d | 16 | SimpleBLE ble("ObCP_CROC_ENSMM"); |
jimbaud | 6:1670244c4eb4 | 17 | |
jimbaud | 6:1670244c4eb4 | 18 | |
jimbaud | 6:1670244c4eb4 | 19 | // GPIO set |
jimbaud | 6:1670244c4eb4 | 20 | |
jimbaud | 6:1670244c4eb4 | 21 | //Interrupt input |
jimbaud | 6:1670244c4eb4 | 22 | |
jimbaud | 6:1670244c4eb4 | 23 | InterruptIn user1(PC_13); //User1 |
jimbaud | 6:1670244c4eb4 | 24 | |
jimbaud | 6:1670244c4eb4 | 25 | //PWM output |
jimbaud | 6:1670244c4eb4 | 26 | |
jimbaud | 6:1670244c4eb4 | 27 | PwmOut PWMoutput(PB_1); //Main PWM output |
jimbaud | 6:1670244c4eb4 | 28 | PwmOut Green(PC_8); //PWM Red LED |
jimbaud | 6:1670244c4eb4 | 29 | PwmOut Red(PC_6); //PWM Green LED |
jimbaud | 6:1670244c4eb4 | 30 | PwmOut Blue(PC_9); //PWM Blue LED |
jimbaud | 6:1670244c4eb4 | 31 | |
jimbaud | 6:1670244c4eb4 | 32 | //Init accelerometer |
janjongboom | 2:12a235e7691a | 33 | |
jimbaud | 6:1670244c4eb4 | 34 | LIS3DH acc(MOSI, MISO, SCLK, CS, LIS3DH_DR_NR_LP_50HZ, LIS3DH_FS_2G); |
jimbaud | 6:1670244c4eb4 | 35 | |
jimbaud | 6:1670244c4eb4 | 36 | // Characteristics Accelerometer input |
jimbaud | 6:1670244c4eb4 | 37 | |
jimbaud | 6:1670244c4eb4 | 38 | SimpleChar<float> accX = ble.readOnly_float(0xA000, 0xA002); |
jimbaud | 6:1670244c4eb4 | 39 | SimpleChar<float> accY = ble.readOnly_float(0xA000, 0xA003); |
jimbaud | 6:1670244c4eb4 | 40 | SimpleChar<float> accZ = ble.readOnly_float(0xA000, 0xA004); |
jimbaud | 6:1670244c4eb4 | 41 | |
jimbaud | 6:1670244c4eb4 | 42 | |
jimbaud | 6:1670244c4eb4 | 43 | // When characteristic LED RGB changing |
jimbaud | 6:1670244c4eb4 | 44 | |
jimbaud | 6:1670244c4eb4 | 45 | void LEDupdate(uint32_t newColor) |
jimbaud | 6:1670244c4eb4 | 46 | { |
jimbaud | 6:1670244c4eb4 | 47 | // read individual bytes |
jimbaud | 6:1670244c4eb4 | 48 | uint8_t* channels = (uint8_t*)&newColor; |
janjongboom | 0:ba1c49874d3c | 49 | |
jimbaud | 6:1670244c4eb4 | 50 | // cast to float, as PwmOut expects a value between 0.0f and 1.0f |
jimbaud | 6:1670244c4eb4 | 51 | Red = static_cast<float>(channels[0]) / 255.0f; |
jimbaud | 6:1670244c4eb4 | 52 | Green = static_cast<float>(channels[1]) / 255.0f; |
jimbaud | 6:1670244c4eb4 | 53 | Blue = static_cast<float>(channels[2]) / 255.0f; |
jimbaud | 6:1670244c4eb4 | 54 | } |
janjongboom | 0:ba1c49874d3c | 55 | |
jimbaud | 6:1670244c4eb4 | 56 | // When characteristic PWM output changing |
jimbaud | 6:1670244c4eb4 | 57 | |
jimbaud | 6:1670244c4eb4 | 58 | void PWMupdate(uint8_t pwmvalue) |
jimbaud | 6:1670244c4eb4 | 59 | { |
jimbaud | 6:1670244c4eb4 | 60 | |
jimbaud | 6:1670244c4eb4 | 61 | // cast to float, as PwmOut expects a value between 0.0f and 1.0f |
jimbaud | 6:1670244c4eb4 | 62 | PWMoutput = static_cast<float>(pwmvalue) / 255.0f; |
jimbaud | 6:1670244c4eb4 | 63 | } |
jimbaud | 6:1670244c4eb4 | 64 | |
jimbaud | 6:1670244c4eb4 | 65 | // When characteristic input changing |
jimbaud | 6:1670244c4eb4 | 66 | void Accupdate() |
jimbaud | 6:1670244c4eb4 | 67 | { |
janjongboom | 0:ba1c49874d3c | 68 | |
jimbaud | 6:1670244c4eb4 | 69 | accX = float(short((acc.read_reg(LIS3DH_OUT_X_H) << 8) | acc.read_reg(LIS3DH_OUT_X_L))) * 0.001F / 15; |
jimbaud | 6:1670244c4eb4 | 70 | accY = float(short((acc.read_reg(LIS3DH_OUT_Y_H) << 8) | acc.read_reg(LIS3DH_OUT_Y_L))) * 0.001F / 15; |
jimbaud | 6:1670244c4eb4 | 71 | accZ = float(short((acc.read_reg(LIS3DH_OUT_Z_H) << 8) | acc.read_reg(LIS3DH_OUT_Z_L))) * 0.001F / 15; |
jimbaud | 6:1670244c4eb4 | 72 | |
jimbaud | 6:1670244c4eb4 | 73 | } |
jimbaud | 6:1670244c4eb4 | 74 | |
jimbaud | 6:1670244c4eb4 | 75 | // Characteritic PWM LED RGB |
jimbaud | 6:1670244c4eb4 | 76 | SimpleChar<uint32_t> color = ble.writeOnly_u32(0x6200, 0x6201, &LEDupdate); |
jimbaud | 6:1670244c4eb4 | 77 | |
jimbaud | 6:1670244c4eb4 | 78 | // Characteristic PWM output |
jimbaud | 6:1670244c4eb4 | 79 | SimpleChar<uint8_t> pwmout = ble.writeOnly_u8(0xA000, 0xA001, &PWMupdate); |
jimbaud | 6:1670244c4eb4 | 80 | |
jimbaud | 6:1670244c4eb4 | 81 | |
jimbaud | 6:1670244c4eb4 | 82 | //Main program |
jimbaud | 6:1670244c4eb4 | 83 | |
jimbaud | 6:1670244c4eb4 | 84 | int main(int, char**) |
jimbaud | 6:1670244c4eb4 | 85 | { |
jimbaud | 6:1670244c4eb4 | 86 | |
jimbaud | 6:1670244c4eb4 | 87 | ble.start(); |
jimbaud | 6:1670244c4eb4 | 88 | Ticker t; |
jimbaud | 6:1670244c4eb4 | 89 | t.attach(&Accupdate, 5.0f); |
jimbaud | 6:1670244c4eb4 | 90 | |
jimbaud | 6:1670244c4eb4 | 91 | while (1) { |
jimbaud | 6:1670244c4eb4 | 92 | ble.waitForEvent(); |
jimbaud | 6:1670244c4eb4 | 93 | |
janjongboom | 0:ba1c49874d3c | 94 | } |
janjongboom | 0:ba1c49874d3c | 95 | } |