Initial

Dependencies:   TextLCD2

Files at this revision

API Documentation at this revision

Comitter:
reedas
Date:
Tue Apr 21 09:58:41 2020 +0000
Parent:
2:3dabedbecf5e
Commit message:
Assignment version

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 3dabedbecf5e -r 6bdfc9e9afc5 main.cpp
--- a/main.cpp	Tue Feb 04 09:30:49 2020 +0000
+++ b/main.cpp	Tue Apr 21 09:58:41 2020 +0000
@@ -147,7 +147,7 @@
 
 #define UNO_CMD (0x10) // Command byte to Uno
 #define UNO_CMD_CONF (0x01) // Configuration data
-#define UNO_ADDR     (0x10) // LM75 address
+#define UNO_ADDR     (0x10) // Uno i2C address
 
 //I2C i2c(P8_1, P8_0);
 I2C i2c(I2C_SDA, I2C_SCL);
@@ -166,7 +166,7 @@
     char data_write[8];
     char data_read[10];
     char buffer[120];
-
+//    i2c.frequency(400000);
     /* Initialise display */
     GUI_Init();
     GUI_Clear();
@@ -210,10 +210,10 @@
             GUI_SetFont(GUI_FONT_10_1);
             GUI_DispStringAt("I2C Data Received  ", 0, 220);
 
-            // read eight bytes
-            // pot value - msb-0, lsb-1
-            // light level - msb-2, lsb-3
-            // temperature - msb-4, lsb-5
+            // read TEN bytes
+            // pot value - msb-1, lsb-0
+            // light level - msb-3, lsb-2
+            // temperature - msb-5, lsb-4
             // sw1 state - 6 - 0-255 based on how long pressed
             // sw2 state - 7 - 0-255 based on how long pressed
             // Humidity - msb-9, lsb-8
@@ -230,6 +230,7 @@
             TempCelsiusDisplay[1] = (tempval / 1000) + 0x30;
             TempCelsiusDisplay[2] = ((tempval % 1000) / 100) + 0x30;
             TempCelsiusDisplay[3] = ((tempval % 1000) % 100 / 10) + 0x30;
+            TempCelsiusDisplay[4] = '.';
             TempCelsiusDisplay[5] = ((tempval % 1000) % 100 % 10) + 0x30;
 
             //Switches
@@ -243,6 +244,7 @@
             //potentiometer value
             int potValue = (int)((int)data_read[1] << 8) | data_read[0];
             
+            // humidity value
             int humidity = (int)((int)data_read[9] << 8) | data_read[8];
 
             // Display result
@@ -257,7 +259,7 @@
             lcd2.locate(0,1);
             lcd2.printf(" %2dC  %2d%c %2d%c %s%s", tempval/10, lightDisplay, 0x25, potValue, 0x25, SW1State?"1":"_", SW2State?"2":"_");
 
-            sprintf(buffer,"Temp is %2dC \nLight Level is %2d%c \nPot Value is %2d%c \nHumidity is %2d%c \n%s \n%s ", tempval/10, lightDisplay, 0x25, potValue, 0x25, humidity, 0x25, SW1State?"SW1 Pressed ":"SW1 Released", SW2State?"SW2 Pressed ":"SW2 Released");
+            sprintf(buffer,"Temp is %2fC \nLight Level is %2d%c \nPot Value is %2d%c \nHumidity is %2d%c \n%s \n%s ", tempval/10, lightDisplay, 0x25, potValue, 0x25, humidity, 0x25, SW1State?"SW1 Pressed ":"SW1 Released", SW2State?"SW2 Pressed ":"SW2 Released");
             GUI_SetFont(GUI_FONT_20_1);
             GUI_DispStringAt(buffer, 0, 40);
         }