Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_6180XA1 mbed
Fork of 247-436-M1-S2-LAB-F302R8 by
Revision 1:90cc91745ff7, committed 2018-02-02
- Comitter:
- YROY2004
- Date:
- Fri Feb 02 10:43:21 2018 +0000
- Parent:
- 0:37eb67c8ebd0
- Child:
- 2:8a29269c7d73
- Commit message:
- pour le lab
Changed in this revision
| X_NUCLEO_6180XA1.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_6180XA1.lib Fri Feb 02 10:43:21 2018 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/ST/code/X_NUCLEO_6180XA1/#32055c2ddac6
--- a/main.cpp Fri Jan 26 13:56:42 2018 +0000
+++ b/main.cpp Fri Feb 02 10:43:21 2018 +0000
@@ -1,10 +1,13 @@
#include "mbed.h"
+#include "XNucleo6180XA1.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
//options de compilation
//#define TEST
-
-#define TFT_SPDF5408
-
//intégration
// représentation
// G: gauche, D: droit, H: haut, B: bas
@@ -37,25 +40,15 @@
#define COMMAND 0
#define DATA 1
-#ifdef TFT_SPDF5408
#define YP A3
#define XM A2
#define YM D9
#define XP D8
-#endif
-
-#ifdef MON_TFT
-#define YP A1 // must be an analog pin, use "An" notation!
-#define YM D7 // can be a digital pin
-#define XP D6 // can be a digital pin
-#define XM A2 // must be an analog pin, use "An" notation!
-#endif
#define TOUCH_SEUIL_HAUT 3000
#define TOUCH_SEUIL_BAS 16
-//tftspfd5408
#define TFTWIDTH 240
#define TFTHEIGHT 320
@@ -67,12 +60,6 @@
#define TFT_NORTH SPFD5408_MADCTL_MY | SPFD5408_MADCTL_BGR
-#if 0
-#define TFT_EAST {SPFD5408_MADCTL_MX | SPFD5408_MADCTL_MY | SPFD5408_MADCTL_MV | SPFD5408_MADCTL_BGR}
-#define TFT_SOUTH {SPFD5408_MADCTL_MX | SPFD5408_MADCTL_BGR}
-#define TFT_WEST {SPFD5408_MADCTL_MV | SPFD5408_MADCTL_BGR}
-#endif
-
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
@@ -85,41 +72,15 @@
#define SPFD5408_SOFTRESET 0x01
#define SPFD5408_SLEEPOUT 0x11
-#if 0
-#define SPFD5408_SLEEPIN 0x10
-#define SPFD5408_NORMALDISP 0x13
-#define SPFD5408_INVERTOFF 0x20
-#define SPFD5408_INVERTON 0x21
-#define SPFD5408_GAMMASET 0x26
-#define SPFD5408_DISPLAYOFF 0x28
-#endif
-
#define SPFD5408_DISPLAYON 0x29
#define SPFD5408_COLADDRSET 0x2A
#define SPFD5408_PAGEADDRSET 0x2B
#define SPFD5408_MEMORYWRITE 0x2C
#define SPFD5408_PIXELFORMAT 0x3A
#define SPFD5408_FRAMECONTROL 0xB1
-#if 0
-#define SPFD5408_DISPLAYFUNC 0xB6
-#define SPFD5408_ENTRYMODE 0xB7
-#define SPFD5408_POWERCONTROL1 0xC0
-#define SPFD5408_POWERCONTROL2 0xC1
-#define SPFD5408_VCOMCONTROL1 0xC5
-#define SPFD5408_VCOMCONTROL2 0xC7
-
-#define SPFD5408_MADCTL 0x36
-#define SPFD5408_MADCTL_MX 0x40
-#define SPFD5408_MADCTL_MV 0x20
-#define SPFD5408_MADCTL_ML 0x10
-#define SPFD5408_MADCTL_RGB 0x00
-#endif
#define SPFD5408_MEMCONTROL 0x36
#define SPFD5408_MADCTL_MY 0x80
#define SPFD5408_MADCTL_BGR 0x08
-#if 0
-#define SPFD5408_MADCTL_MH 0x04
-#endif
#define IDLE 1
#define ACTIVE 0
@@ -128,6 +89,13 @@
#define TEMPS 40
+//VL6180X
+#define VL6180X_I2C_SDA D14
+#define VL6180X_I2C_SCL D15
+
+#define VL6180X_I2C_SDA_MODE PullUp
+#define VL6180X_I2C_SCL_MODE PullUp
+
//integration
@@ -140,6 +108,8 @@
#define YT_H 600
#define YT_B 3700
+#define MODE_COULEUR_CONSTANTE 0
+#define MODE_COULEUR_VARIABLE 1
//definitions de variables
//touchscreen
uint16_t x;
@@ -153,13 +123,21 @@
DigitalOut pinCS(LCD_CS); //PB_0;
DigitalOut pinReset(LCD_RESET); //PC_1;
+//VL6180X
+DigitalOut enableVL6180X(D12);
+static XNucleo6180XA1 *board = NULL;
+uint32_t dist;
+
+
//integration
-Serial pc(SERIAL_TX, SERIAL_RX, 9600);
+#ifdef TEST
+ Serial pc(USBTX, USBRX, 9600); //SERIAL_TX, SERIAL_RX, 9600);
+#endif
DigitalOut myled(LED1);
uint16_t couleurVariable;
uint16_t tableDeCouleur[]=
{
- WHITE, YELLOW, GREEN, BLUE, CYAN, MAGENTA, RED
+ BLACK, RED, YELLOW, GREEN, CYAN, BLUE, MAGENTA, WHITE
};
@@ -396,19 +374,62 @@
uint16_t determineLaCouleur(void)
{
- return tableDeCouleur[3];
+ board->sensor_top->get_distance(&dist);
+ if (dist > 210) //en millimetres
+ {
+ dist = 210;
+ }
+// board->sensor_top->get_lux(&lux);
+
+ return tableDeCouleur[(int)(dist/30)];
}
int main()
-{
+{
+//variables locales du touchscreen
uint16_t couleur;
+
+//variables locales du tftspfd5408
+
+//variables locales pour le VL6180X
+int status;
+uint32_t lux;
+
+DevI2C *device_i2c = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL);
+//variables locales pour l'integration
+uint32_t mode;
+
//initialisation du touchscreen
restoreXY();
//initialisation du tftspfd5408
begin();
+//initialisation du VL6180X
+// printf ("Initialisation *********\n");
+//yr
+// pin_mode(VL6180X_I2C_SDA, (PinMode)PullUp);
+// pin_mode(VL6180X_I2C_SCL, (PinMode)PullUp);
+
+ enableVL6180X = 1;
+ wait_ms(1);
+ enableVL6180X = 0;
+ wait_ms(1);
+ enableVL6180X = 1;
+ wait_ms(1);
+
+ /* Creates the 6180XA1 expansion board singleton obj. */
+ board = XNucleo6180XA1::instance(device_i2c, D11, D10, D13, D2);
+
+ /* Initializes the 6180XA1 expansion board with default values. */
+ status = board->init_board();
+ if (status) {
+ printf("Failed to init board!\n\r");
+ return 0;
+ }
+
//intégration
+ mode = MODE_COULEUR_CONSTANTE;
couleur = RED;
couleurVariable = BLUE;
fillRect(0, 0, 240, 280, BLACK); //surface de dessin
@@ -428,7 +449,11 @@
fillRect(81, 282, 10, 10, GREEN); //couleur rouge par défaut
while(1) {
-
+
+#ifdef TEST
+ printf ("Distance: %d, Lux: %d\n\r", dist, lux);
+#endif
+
//tâches du touchscreen
myled = !myled;
@@ -440,7 +465,7 @@
//tâches d'intégration
couleurVariable = determineLaCouleur();
- fillRect(228, 282, 10, 10, couleurVariable); //indicateur de couleur
+// fillRect(228, 282, 10, 10, couleurVariable); //indicateur de couleur
if ((z > TOUCH_SEUIL_BAS)&&(z < TOUCH_SEUIL_HAUT))
{
@@ -458,7 +483,14 @@
#endif
if (v < 280)
{
- fillRect(u, v, 1, 1, couleur);
+ if (mode == MODE_COULEUR_CONSTANTE)
+ {
+ fillRect(u, v, 3, 3, couleur);
+ }
+ else
+ {
+ fillRect(u, v, 3, 3, couleurVariable);
+ }
}
else
{
@@ -470,21 +502,26 @@
{
if (u < 160)
{
+ mode = MODE_COULEUR_CONSTANTE;
//indicateur RED
fillRect(81, 282, 10, 10, GREEN); //couleur rouge par défaut
- fillRect(161,282, 10, 10, couleurVariable);
+ fillRect(161,282, 10, 10, BLUE);
- couleur = RED;
+#ifdef TEST
pc.printf("couleur: rouge\n\r");
+#endif
}
else
{
+ mode = MODE_COULEUR_VARIABLE;
//indicateur AUTRE
- fillRect(161, 282, 77, 36, couleurVariable);
- fillRect(161, 282, 10, 10, GREEN); //bouton bleu pale
fillRect(81, 282, 10, 10, RED);
- couleur = couleurVariable;
+ fillRect(161, 282, 77, 36, BLUE);
+ fillRect(161, 282, 10, 10, GREEN);
+
+#ifdef TEST
pc.printf("couleur variable\n\r");
+#endif
}
}
}
