Nucleo_L432_OLED_ADC

Dependencies:   Adafruit_GFX mbed

Files at this revision

API Documentation at this revision

Comitter:
pythonworld
Date:
Fri Jun 02 00:27:26 2017 +0000
Parent:
4:573208af69ba
Commit message:
only ADXL335 support

Changed in this revision

main.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
diff -r 573208af69ba -r e4f8eaef10c6 main.cpp
--- a/main.cpp	Thu Oct 27 13:35:03 2016 +0000
+++ b/main.cpp	Fri Jun 02 00:27:26 2017 +0000
@@ -1,21 +1,18 @@
 #include "mbed.h"
-#include "Adafruit_SSD1306.h"
+//#include "Adafruit_SSD1306.h"
 //------------------------------------
 // Hyperterminal configuration
 // 9600 bauds, 8-bit data, no parity
 //------------------------------------
+// SSD1306 OLED AND Nucleo L432KC
 
-// SSD1306 OLED AND Nucleo L432KC
-// 2016.10.23
-// 2016.10.23 changed
-#define offset_voltage 1570
-#define sensitivity 330
-Serial pc(SERIAL_TX, SERIAL_RX);
-
-DigitalOut myled(LED3);
-AnalogIn adc1(A0);
-AnalogIn adc2(A1);
-AnalogIn adc3(A5);
+#define Number 2048
+#define XS 0.3235
+#define YS 0.3235
+#define ZS 0.3200
+#define XB 1.5675
+#define YB 1.5465
+#define ZB 1.6100
 
 #define DO A4
 #define DI A6
@@ -23,17 +20,27 @@
 #define DC D11
 #define RST D7
 
-class SPIPreInit : public SPI
-{
-public:
-    SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) {
-        format(8,3);
-        frequency(2000000);
-    };
-};
+Serial pc(SERIAL_TX, SERIAL_RX);
+DigitalOut myled(LED3);
+AnalogIn adc1(A0);
+AnalogIn adc2(A1);
+AnalogIn adc3(A5);
+float xa[Number],ya[Number],za[Number];
+
+
 
-SPIPreInit mySpi(DI,NC,DO);
-Adafruit_SSD1306_Spi oled(mySpi,DC,RST,CS,64,128);
+//
+//class SPIPreInit : public SPI
+//{
+//public:
+//    SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) {
+//        format(8,3);
+//        frequency(2000000);
+//    };
+//};
+//
+//SPIPreInit mySpi(DI,NC,DO);
+//Adafruit_SSD1306_Spi oled(mySpi,DC,RST,CS,64,128);
 
 
 
@@ -42,25 +49,38 @@
     int x=0;
 
 
-    oled.clearDisplay();
-    oled.setTextSize(2);
+//    oled.clearDisplay();
+//    oled.setTextSize(2);
+
     while(1) {
-        x++;
-        oled.printf("X %2.2lf g\r\n",double(adc1.read()*3300-offset_voltage)/sensitivity);
-        oled.printf("Y %2.2lf g\r\n",double(adc2.read()*3300-offset_voltage)/sensitivity);
-        oled.printf("Z %2.2lf g\r\n",double(adc3.read()*3300-offset_voltage)/sensitivity);
+
+//        oled.printf("X %2.2lf g\r\n",double(adc1.read()*3300-offset_voltage)/sensitivity);
+//        oled.printf("Y %2.2lf g\r\n",double(adc2.read()*3300-offset_voltage)/sensitivity);
+//        oled.printf("Z %2.2lf g\r\n",double(adc3.read()*3300-offset_voltage)/sensitivity);
+//        oled.display();
+
+        wait_us(500);
+
+        xa[x]=adc1.read()*3300/1000;
+        ya[x]=adc2.read()*3300/1000;
+        za[x]=adc3.read()*3300/1000;
 
-        oled.display();
-        wait(0.5);
+        x++;
+        myled = !myled;
+
+        if(x>=Number) {
 
-        pc.printf("X %2.3f V\r\n", adc1.read()*3300/1000);
-        pc.printf("Y %2.3f V\r\n", adc2.read()*3300/1000);
-        pc.printf("Z %2.3f V\r\n", adc3.read()*3300/1000);
+            myled = !myled;
+            int c=0;
+            while(c++<1) {
 
-//  myled = !myled;
-        if(x>0) {
-            oled.setTextCursor(0,0);
-            oled.clearDisplay();
+                pc.printf("X %2.3f g\r\n", (xa[c]-XB)/XS);
+                pc.printf("Y %2.3f g\r\n", (ya[c]-YB)/YS);
+                pc.printf("Z %2.3f g\r\n", (za[c]-ZB)/ZS);
+                pc.printf("-----------------\r\n");
+
+                wait(2);
+            }
             x=0;
         }
     }
diff -r 573208af69ba -r e4f8eaef10c6 mbed.bld
--- a/mbed.bld	Thu Oct 27 13:35:03 2016 +0000
+++ b/mbed.bld	Fri Jun 02 00:27:26 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file
+https://mbed.org/users/mbed_official/code/mbed/builds/4eea097334d6
\ No newline at end of file