Sweep a servo according to Proximity sensor measure
Dependencies: Servo X_NUCLEO_6180XA1 mbed
Fork of HelloWorld_6180XA1 by
main.cpp@5:fa65d931bd96, 2015-09-25 (annotated)
- Committer:
- gallonm
- Date:
- Fri Sep 25 12:14:00 2015 +0200
- Revision:
- 5:fa65d931bd96
- Parent:
- 4:ccd62fd7e137
- Child:
- 6:f253ca7919af
update file
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gallonm | 0:83c628a58feb | 1 | #include "mbed.h" |
gallonm | 4:ccd62fd7e137 | 2 | #include "vl6180x_class.h" |
gallonm | 5:fa65d931bd96 | 3 | #include "STMPE1600_class.h" |
gallonm | 0:83c628a58feb | 4 | |
gallonm | 4:ccd62fd7e137 | 5 | #include <string.h> |
gallonm | 4:ccd62fd7e137 | 6 | #include <stdlib.h> |
gallonm | 4:ccd62fd7e137 | 7 | #include <stdio.h> |
gallonm | 4:ccd62fd7e137 | 8 | |
gallonm | 5:fa65d931bd96 | 9 | #define VL6180X_I2C_SDA I2C_SDA |
gallonm | 5:fa65d931bd96 | 10 | #define VL6180X_I2C_SCL I2C_SCL |
gallonm | 5:fa65d931bd96 | 11 | |
gallonm | 5:fa65d931bd96 | 12 | |
gallonm | 5:fa65d931bd96 | 13 | /* Enable e disable function -------------------------------------------------------*/ |
gallonm | 5:fa65d931bd96 | 14 | #define EXPANDER_I2C_ADDRESS (0x42*2) |
gallonm | 5:fa65d931bd96 | 15 | #define GPMR 0x10 |
gallonm | 5:fa65d931bd96 | 16 | #define GPSR 0x12 |
gallonm | 5:fa65d931bd96 | 17 | #define GPDR 0x14 |
gallonm | 5:fa65d931bd96 | 18 | |
gallonm | 5:fa65d931bd96 | 19 | #define V2_CHIPEN (1<<12) |
gallonm | 5:fa65d931bd96 | 20 | #define V2_CHIPEN_B (1<<13) |
gallonm | 5:fa65d931bd96 | 21 | #define V2_CHIPEN_L (1<<14) |
gallonm | 5:fa65d931bd96 | 22 | #define V2_CHIPEN_R (1<<15) |
gallonm | 5:fa65d931bd96 | 23 | |
gallonm | 5:fa65d931bd96 | 24 | /*----------------------------------------------------------------------------------*/ |
gallonm | 5:fa65d931bd96 | 25 | |
gallonm | 4:ccd62fd7e137 | 26 | void OnErrLog(void){}; |
gallonm | 5:fa65d931bd96 | 27 | void DISP_ExecLoopBody(void){}; |
gallonm | 0:83c628a58feb | 28 | |
gallonm | 4:ccd62fd7e137 | 29 | int main() |
gallonm | 5:fa65d931bd96 | 30 | { |
gallonm | 5:fa65d931bd96 | 31 | uint8_t buf[8]={1,1,0,0,0,0,0,0}; |
gallonm | 5:fa65d931bd96 | 32 | |
gallonm | 5:fa65d931bd96 | 33 | |
gallonm | 5:fa65d931bd96 | 34 | uint8_t x=0xFF; |
gallonm | 5:fa65d931bd96 | 35 | uint8_t y=0xF7; |
gallonm | 5:fa65d931bd96 | 36 | uint8_t z=0x80; |
gallonm | 5:fa65d931bd96 | 37 | uint8_t k=0x17; |
gallonm | 5:fa65d931bd96 | 38 | uint8_t g=0xE7; |
gallonm | 5:fa65d931bd96 | 39 | |
gallonm | 5:fa65d931bd96 | 40 | DevI2C device_i2c(VL6180X_I2C_SDA, VL6180X_I2C_SCL); |
gallonm | 5:fa65d931bd96 | 41 | STMPE1600DigiOut exp(device_i2c, GPIO_12, STMPE1600_DEF_DEVICE_ADDRESS); |
gallonm | 5:fa65d931bd96 | 42 | VL6180X sensor1(device_i2c, exp); |
gallonm | 5:fa65d931bd96 | 43 | |
gallonm | 5:fa65d931bd96 | 44 | |
gallonm | 5:fa65d931bd96 | 45 | //imposto GPIO di input e output |
gallonm | 5:fa65d931bd96 | 46 | device_i2c.i2c_write(&x, 0x42*2, 0x14, 1); |
gallonm | 5:fa65d931bd96 | 47 | device_i2c.i2c_write(&y, 0x42*2, 0x15, 1); |
gallonm | 5:fa65d931bd96 | 48 | //disabilito i display e abilito il GPIO0 del sensore top |
gallonm | 5:fa65d931bd96 | 49 | device_i2c.i2c_write(&z, 0x42*2, 0x12, 1); |
gallonm | 5:fa65d931bd96 | 50 | device_i2c.i2c_write(&g, 0x42*2, 0x13, 1); //spengo gpio0 |
gallonm | 5:fa65d931bd96 | 51 | device_i2c.i2c_write(&k, 0x42*2, 0x13, 1); //accendo gpio0 |
gallonm | 5:fa65d931bd96 | 52 | |
gallonm | 5:fa65d931bd96 | 53 | //VL6180x_I2CRead(0x29, (uint16_t)0x000, buf, 2); |
gallonm | 5:fa65d931bd96 | 54 | //VL6180x_I2CRead(0x29, (uint16_t)0x212, buf+1, 2); |
gallonm | 5:fa65d931bd96 | 55 | //buf[2]=0x32; |
gallonm | 5:fa65d931bd96 | 56 | //VL6180x_I2CWrite(0x29, (uint16_t)0x0212, buf+2, 1); |
gallonm | 5:fa65d931bd96 | 57 | //VL6180x_I2CRead(0x32, (uint16_t)0x212, buf+3, 2); |
gallonm | 5:fa65d931bd96 | 58 | |
gallonm | 5:fa65d931bd96 | 59 | buf[0]=sensor1.Init(); |
gallonm | 5:fa65d931bd96 | 60 | buf[1]=sensor1.ReadID(); |
gallonm | 5:fa65d931bd96 | 61 | //buf[2]=sensor1.Prepare(); |
gallonm | 5:fa65d931bd96 | 62 | //sensor1.~VL6180X(); |
gallonm | 5:fa65d931bd96 | 63 | |
gallonm | 5:fa65d931bd96 | 64 | |
gallonm | 5:fa65d931bd96 | 65 | /* |
gallonm | 5:fa65d931bd96 | 66 | X_NUCLEO_6180XA1 board; |
gallonm | 5:fa65d931bd96 | 67 | |
gallonm | 5:fa65d931bd96 | 68 | status=board.vl6180x_top.RdByte(IDENTIFICATION_MODEL_ID, &buffer); |
gallonm | 5:fa65d931bd96 | 69 | if(!status) |
gallonm | 5:fa65d931bd96 | 70 | { |
gallonm | 5:fa65d931bd96 | 71 | board.vl6180x_top.SetPresent(); |
gallonm | 5:fa65d931bd96 | 72 | board.vl6180x_top.SetDeviceID(i); |
gallonm | 5:fa65d931bd96 | 73 | if(!(board.vl6180x_top.Init()||board.vl6180x_top.Prepare())) |
gallonm | 5:fa65d931bd96 | 74 | { |
gallonm | 5:fa65d931bd96 | 75 | board.vl6180x_top.SetReady(); |
gallonm | 5:fa65d931bd96 | 76 | status=board.vl6180x_top.SetI2CAddress(final_i2c_address); |
gallonm | 5:fa65d931bd96 | 77 | if(status) |
gallonm | 5:fa65d931bd96 | 78 | errore su scrittura indirizzo i2c |
gallonm | 5:fa65d931bd96 | 79 | } |
gallonm | 5:fa65d931bd96 | 80 | else |
gallonm | 5:fa65d931bd96 | 81 | errore su init o prepare |
gallonm | 5:fa65d931bd96 | 82 | } |
gallonm | 5:fa65d931bd96 | 83 | i++; |
gallonm | 5:fa65d931bd96 | 84 | |
gallonm | 5:fa65d931bd96 | 85 | //stessa cosa per gli altri sensori (left, bottom e right) |
gallonm | 5:fa65d931bd96 | 86 | |
gallonm | 5:fa65d931bd96 | 87 | */ |
gallonm | 5:fa65d931bd96 | 88 | |
gallonm | 4:ccd62fd7e137 | 89 | } |
gallonm | 5:fa65d931bd96 | 90 | |
gallonm | 5:fa65d931bd96 | 91 | |
gallonm | 5:fa65d931bd96 | 92 |