k

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
RobotManYt
Date:
Fri May 24 14:38:11 2019 +0000
Commit message:
l

Changed in this revision

main2.cpp Show annotated file Show diff for this revision Revisions of this file
main3.cpp Show annotated file Show diff for this revision Revisions of this file
main4.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main2.cpp	Fri May 24 14:38:11 2019 +0000
@@ -0,0 +1,20 @@
+#include "mbed.h"
+ 
+AnalogIn analog_value(A0);          // Définition broche analogique sur PA_0
+Serial pc(SERIAL_TX, SERIAL_RX);    // Définition d'un port série avec l'ordinateur
+Ticker printTMP;                    // Définition d'un ticker
+
+uint8_t tmp = 0;        // Définition variable tmp; GLOBAL; tmp = Température
+
+void print(){
+    pc.printf("Temperature = %u C", tmp);   // Affiche tmp/température
+}
+
+int main() {
+    printTMP.attach(&print, 0.2);
+    
+    while(1) {
+        int16_t meas = analog_value.read() * 3300;      // Lecture du port analogique
+        tmp = (uint8_t)(((float)meas / 10) - 273.15);   // mV --> °C
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main3.cpp	Fri May 24 14:38:11 2019 +0000
@@ -0,0 +1,21 @@
+#include "mbed.h"
+ 
+SPI spi(PA_7, PA_6, PA_5);  // mosi, miso, sclk
+DigitalOut cs(PA_8);        // Chip Select du MCP42010
+AnalogIn analog_value(A0);  // Broche PA_0 en mode analogique
+
+
+int main() {
+    spi.format(8,3);            // Mode du SPI
+    spi.frequency(1000000);     // Féquence du SPI
+    
+    while(1) {
+        cs = 0;     // Active le MCP42010
+
+        spi.write(0b00010001);      // Indique le registre du PW0 en écriture
+     
+        spi.write((uint8_t)(analog_value.read() * 255));    // Écrit la valeur souhaité sur PW0
+
+        cs = 1;     // Désactive le MCP42010
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main4.cpp	Fri May 24 14:38:11 2019 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include "math.h"
+#include "string"
+#include "sstream"
+
+#define LCD          0x50   // Adresse de LCD
+#define LCD_ON       0x41   // Registre pour allumer l'écran
+#define LCD_CURSOR   0X45   // Registre de positionnement du curseur
+#define LCD_CLEAR    0x51   // Registre pour effacer l'écran
+#define LCD_CMD      0xFE   // Registre de commande
+
+AnalogIn analog_value(A0);
+I2C i2c(I2C_SDA, I2C_SCL);
+
+int main() {
+    i2c.frequency(100000);          // Fréquence du I2C à 100KHz
+    
+    char commande[4] = {LCD_CMD, LCD_ON, LCD_CMD, LCD_CLEAR};   // Initialise l'écran
+    i2c.write(LCD, commande, 4);                                // Initialise l'écran
+    
+    while(1) {
+        float analog = analog_value.read() * 3.3;   // Lecture de la tension sur A0
+        
+        stringstream ss;                // *** float --> string *** //
+        ss << analog;                   // *** float --> string *** //
+        string txt = ss.str() + " V";   // *** Composition du string *** //
+        
+        char data[txt.size() + 3];                  // ******************************** //
+        data[0] = LCD_CMD;                          //
+        data[1] = LCD_CURSOR;                       //
+        data[2] = 0;                                // String --> char +
+        for(uint8_t i = 0; i < txt.size(); i++){    // Positionnement du curseur à (0,0)
+            data[i + 3] = txt[i];                   //
+        }                                           // ******************************** //
+        
+        i2c.write(LCD, data, txt.size());       // Écriture sur l'écran
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri May 24 14:38:11 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file