display a graph of temperature from the NTC on the OLED

Dependencies:   SSD1308_128x64_I2C Grove_temperature

Files at this revision

API Documentation at this revision

Comitter:
dcj001
Date:
Wed Dec 11 16:38:09 2019 +0000
Commit message:
display a graph of temperature from the NTC on the OLED

Changed in this revision

Grove_temperature.lib Show annotated file Show diff for this revision Revisions of this file
SSD1308_128x64_I2C.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
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mysource/wave.cpp Show annotated file Show diff for this revision Revisions of this file
mysource/wave.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 50a79669d4e7 Grove_temperature.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Grove_temperature.lib	Wed Dec 11 16:38:09 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/MACRUM/code/Grove_temperature/#aee37a51ccbb
diff -r 000000000000 -r 50a79669d4e7 SSD1308_128x64_I2C.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SSD1308_128x64_I2C.lib	Wed Dec 11 16:38:09 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/wim/code/SSD1308_128x64_I2C/#e564cde8e03e
diff -r 000000000000 -r 50a79669d4e7 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 11 16:38:09 2019 +0000
@@ -0,0 +1,84 @@
+#include "mbed.h"
+#include "SSD1308.h"
+#include "wave.h"
+#include "Grove_temperature.h"
+
+#define NUM_TEMP 64 //The number of points that will be displayed on the OLED
+
+AnalogIn varRes(A3);    //variable resistor
+Grove_temperature temp_obj(A1);   //Create a Crove_temperature object named "temp_obj", it's connected to Pin  A1.
+I2C i2c(PB_9,PB_8);               //The OLED uses port I2C to connect to the L073RZ
+SSD1308 oled = SSD1308(&i2c, SSD1308_SA0);
+
+void tempArrayInit(Temperature *p);         //temperature struct initialization
+void tempArrayRefresh(Temperature *p);      //temperature struct refresh
+void tempArrayDisplayOnOLED(Temperature *p);//temperature struct display the point on the OLED
+
+int main() {
+    Temperature t[NUM_TEMP];  //temperature array
+    char buffer[10];          //store a string
+    int interval;               //refresh time
+             
+    tempArrayInit(t);           //temperature array initialization
+    oled.clearDisplay();
+    while(1){
+        interval = (int)(varRes.read() * 200);  //variable resistor control the refresh speed
+        wait_ms(interval);        
+        
+        tempArrayRefresh(t);    //refresh the array
+        tempArrayDisplayOnOLED(t);      //display the pixel about the tempearture
+    
+        sprintf(buffer," T:%2dC",t[NUM_TEMP - 1].u8_temperature);     //sprintf the temperature to the buffer
+        oled.writeString(3,8,buffer);  
+//        sprintf(buffer," t:%3dms",interval);     //sprintf the temperature to the buffer
+//        oled.writeString(5,8,buffer);                
+    }
+}
+
+void tempArrayInit(Temperature *p)
+{
+    uint8_t i;
+    for(i = 0;i < NUM_TEMP;i++){
+        p[i].u8_col = i;
+        p[i].u8_temperature = i % 64;
+    }
+}
+void tempArrayRefresh(Temperature *p)
+{
+    //refresh array
+    uint8_t i;
+    for(i = 0;i < (NUM_TEMP - 1);i++){
+        p[i].u8_page = p[i + 1].u8_page;
+        //don't refresh the column
+        //p[i].u8_col = p[i + 1].u8_col;
+        p[i].u8_temperature = p[i + 1].u8_temperature;
+        p[i].u8_value = p[i + 1].u8_value;
+    }
+
+    //get new value
+    p[NUM_TEMP - 1].u8_temperature = (uint8_t)(temp_obj.getTemperature());
+    
+    //calculate value
+    p[NUM_TEMP - 1].calcPage();
+    p[NUM_TEMP - 1].calcValue();
+}
+
+void tempArrayDisplayOnOLED(Temperature *p)
+{
+    uint8_t i;
+    
+    for(i = 0;i < NUM_TEMP;i++){
+        
+        oled.writeBitmap(&p[i].u8_value,p[i].u8_page,p[i].u8_page,p[i].u8_col,p[i].u8_col);
+        /* clear the data on other pages withins the same column*/
+        for(uint8_t j = 0;j < 8;j++){
+            if(j == p[i].u8_page){
+                continue;
+            }    
+            else{
+                oled.writeBitmap(0,j,j,p[i].u8_col,p[i].u8_col);
+            }
+        }
+        
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 50a79669d4e7 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Dec 11 16:38:09 2019 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#a1c0840b3d69060e5eb708edb18358e424a40f51
diff -r 000000000000 -r 50a79669d4e7 mysource/wave.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mysource/wave.cpp	Wed Dec 11 16:38:09 2019 +0000
@@ -0,0 +1,29 @@
+#include "wave.h"
+
+Temperature::Temperature(void)
+{
+    u8_page = 7;
+    u8_col = 127;
+    u8_temperature = 0;
+    u8_value = 0;
+}
+
+Temperature::~Temperature(void)
+{
+    
+}
+
+void Temperature::calcPage(void)        //calculate the display page of this temperature
+{
+    uint8_t tmp;
+    tmp = u8_temperature / 8;
+    u8_page = 7 - tmp;  //7 - tmp
+}
+
+void Temperature::calcValue(void)       //calculate the I2C value of this temperature
+{
+    uint8_t index;
+    
+    index = 7 - ( u8_temperature % 8 );
+    u8_value = (0x01) << index;
+}
\ No newline at end of file
diff -r 000000000000 -r 50a79669d4e7 mysource/wave.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mysource/wave.h	Wed Dec 11 16:38:09 2019 +0000
@@ -0,0 +1,19 @@
+#ifndef WAVE_H
+#define WAVE_H
+
+#include "mbed.h"
+
+class Temperature{
+public:
+    Temperature();
+    ~Temperature();
+    void calcPage(void);
+    void calcValue(void);
+    
+    uint8_t u8_page; // 0 ~ 7   The display page
+    uint8_t u8_col; // 0 ~127
+    uint8_t u8_temperature; // 0 ~ 64
+    uint8_t u8_value; //I2c data that will be sent to I2C
+};
+
+#endif
\ No newline at end of file