Sweep a servo according to Proximity sensor measure

Dependencies:   Servo X_NUCLEO_6180XA1 mbed

Fork of HelloWorld_6180XA1 by ST

Committer:
licio.mapelli@st.com
Date:
Tue Sep 29 14:51:10 2015 +0200
Revision:
6:f253ca7919af
Parent:
5:fa65d931bd96
Child:
7:865f0c23a183
test GPIOExp

Who changed what in which revision?

UserRevisionLine numberNew 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};
licio.mapelli@st.com 6:f253ca7919af 32 static uint32_t tmp;
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
licio.mapelli@st.com 6:f253ca7919af 40 DigitalOut led (LED2);
licio.mapelli@st.com 6:f253ca7919af 41 led=1;
licio.mapelli@st.com 6:f253ca7919af 42
gallonm 5:fa65d931bd96 43 DevI2C device_i2c(VL6180X_I2C_SDA, VL6180X_I2C_SCL);
licio.mapelli@st.com 6:f253ca7919af 44
licio.mapelli@st.com 6:f253ca7919af 45 STMPE1600DigiOut gpio0(device_i2c, GPIO_0, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 46 STMPE1600DigiOut gpio1(device_i2c, GPIO_1, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 47 STMPE1600DigiOut gpio2(device_i2c, GPIO_2, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 48 STMPE1600DigiOut gpio3(device_i2c, GPIO_3, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 49 STMPE1600DigiOut gpio4(device_i2c, GPIO_4, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 50 STMPE1600DigiOut gpio5(device_i2c, GPIO_5, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 51 STMPE1600DigiOut gpio6(device_i2c, GPIO_6, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 52 STMPE1600DigiOut gpio7(device_i2c, GPIO_7, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 53 STMPE1600DigiOut gpio8(device_i2c, GPIO_8, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 54
licio.mapelli@st.com 6:f253ca7919af 55 STMPE1600DigiOut gpio9(device_i2c, GPIO_9, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 56 STMPE1600DigiOut gpio10(device_i2c, GPIO_10, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 57 STMPE1600DigiIn gpio11(device_i2c, GPIO_11, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 58 STMPE1600DigiOut gpio12(device_i2c, GPIO_12, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 59 STMPE1600DigiOut gpio13(device_i2c, GPIO_13, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 60 STMPE1600DigiOut gpio14(device_i2c, GPIO_14, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 61 STMPE1600DigiOut gpio15(device_i2c, GPIO_15, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 62
licio.mapelli@st.com 6:f253ca7919af 63
licio.mapelli@st.com 6:f253ca7919af 64
licio.mapelli@st.com 6:f253ca7919af 65 gpio0 = 0; gpio1 = 1; gpio2 = 1; gpio3 = 1; gpio4 = 1; gpio5 = 1; gpio6 = 1; gpio7 = 0;
licio.mapelli@st.com 6:f253ca7919af 66 gpio8 = 1; gpio9 = 1; gpio10 = 1; gpio12 = 1; gpio13 = 1; gpio14 = 1; gpio15 = 1;
licio.mapelli@st.com 6:f253ca7919af 67
licio.mapelli@st.com 6:f253ca7919af 68 //STMPE1600DigiOut * p_exp = new STMPE1600DigiOut(device_i2c, GPIO_12, STMPE1600_DEF_DEVICE_ADDRESS);
licio.mapelli@st.com 6:f253ca7919af 69
licio.mapelli@st.com 6:f253ca7919af 70 VL6180X sensor1(device_i2c, gpio12);
licio.mapelli@st.com 6:f253ca7919af 71
licio.mapelli@st.com 6:f253ca7919af 72 sensor1.VL6180x_On();
licio.mapelli@st.com 6:f253ca7919af 73 // tmp = sensor1.Init();
licio.mapelli@st.com 6:f253ca7919af 74
licio.mapelli@st.com 6:f253ca7919af 75 uint8_t id=0;
licio.mapelli@st.com 6:f253ca7919af 76 id = sensor1.ReadID(); // read id to test
licio.mapelli@st.com 6:f253ca7919af 77
licio.mapelli@st.com 6:f253ca7919af 78 // VL6180X sensor1(device_i2c, exp);
gallonm 5:fa65d931bd96 79
licio.mapelli@st.com 6:f253ca7919af 80
licio.mapelli@st.com 6:f253ca7919af 81 while (1);
gallonm 5:fa65d931bd96 82
gallonm 5:fa65d931bd96 83 //imposto GPIO di input e output
gallonm 5:fa65d931bd96 84 device_i2c.i2c_write(&x, 0x42*2, 0x14, 1);
gallonm 5:fa65d931bd96 85 device_i2c.i2c_write(&y, 0x42*2, 0x15, 1);
gallonm 5:fa65d931bd96 86 //disabilito i display e abilito il GPIO0 del sensore top
gallonm 5:fa65d931bd96 87 device_i2c.i2c_write(&z, 0x42*2, 0x12, 1);
gallonm 5:fa65d931bd96 88 device_i2c.i2c_write(&g, 0x42*2, 0x13, 1); //spengo gpio0
gallonm 5:fa65d931bd96 89 device_i2c.i2c_write(&k, 0x42*2, 0x13, 1); //accendo gpio0
gallonm 5:fa65d931bd96 90
gallonm 5:fa65d931bd96 91 //VL6180x_I2CRead(0x29, (uint16_t)0x000, buf, 2);
gallonm 5:fa65d931bd96 92 //VL6180x_I2CRead(0x29, (uint16_t)0x212, buf+1, 2);
gallonm 5:fa65d931bd96 93 //buf[2]=0x32;
gallonm 5:fa65d931bd96 94 //VL6180x_I2CWrite(0x29, (uint16_t)0x0212, buf+2, 1);
gallonm 5:fa65d931bd96 95 //VL6180x_I2CRead(0x32, (uint16_t)0x212, buf+3, 2);
gallonm 5:fa65d931bd96 96
gallonm 5:fa65d931bd96 97 buf[0]=sensor1.Init();
gallonm 5:fa65d931bd96 98 buf[1]=sensor1.ReadID();
gallonm 5:fa65d931bd96 99 //buf[2]=sensor1.Prepare();
gallonm 5:fa65d931bd96 100 //sensor1.~VL6180X();
gallonm 5:fa65d931bd96 101
gallonm 5:fa65d931bd96 102
gallonm 5:fa65d931bd96 103 /*
gallonm 5:fa65d931bd96 104 X_NUCLEO_6180XA1 board;
gallonm 5:fa65d931bd96 105
gallonm 5:fa65d931bd96 106 status=board.vl6180x_top.RdByte(IDENTIFICATION_MODEL_ID, &buffer);
gallonm 5:fa65d931bd96 107 if(!status)
gallonm 5:fa65d931bd96 108 {
gallonm 5:fa65d931bd96 109 board.vl6180x_top.SetPresent();
gallonm 5:fa65d931bd96 110 board.vl6180x_top.SetDeviceID(i);
gallonm 5:fa65d931bd96 111 if(!(board.vl6180x_top.Init()||board.vl6180x_top.Prepare()))
gallonm 5:fa65d931bd96 112 {
gallonm 5:fa65d931bd96 113 board.vl6180x_top.SetReady();
gallonm 5:fa65d931bd96 114 status=board.vl6180x_top.SetI2CAddress(final_i2c_address);
gallonm 5:fa65d931bd96 115 if(status)
gallonm 5:fa65d931bd96 116 errore su scrittura indirizzo i2c
gallonm 5:fa65d931bd96 117 }
gallonm 5:fa65d931bd96 118 else
gallonm 5:fa65d931bd96 119 errore su init o prepare
gallonm 5:fa65d931bd96 120 }
gallonm 5:fa65d931bd96 121 i++;
gallonm 5:fa65d931bd96 122
gallonm 5:fa65d931bd96 123 //stessa cosa per gli altri sensori (left, bottom e right)
gallonm 5:fa65d931bd96 124
gallonm 5:fa65d931bd96 125 */
gallonm 5:fa65d931bd96 126
gallonm 4:ccd62fd7e137 127 }
gallonm 5:fa65d931bd96 128
gallonm 5:fa65d931bd96 129
gallonm 5:fa65d931bd96 130