code

Dependencies:   BME280 BMP280 TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
ckalintra
Date:
Sat Jan 06 17:28:05 2018 +0000
Commit message:
code;

Changed in this revision

BME280.lib Show annotated file Show diff for this revision Revisions of this file
BMP280.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
data.h Show annotated file Show diff for this revision Revisions of this file
date.h 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.bld Show annotated file Show diff for this revision Revisions of this file
putty.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 7023c3f98f36 BME280.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BME280.lib	Sat Jan 06 17:28:05 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/MACRUM/code/BME280/#c1f1647004c4
diff -r 000000000000 -r 7023c3f98f36 BMP280.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BMP280.lib	Sat Jan 06 17:28:05 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/charly/code/BMP280/#d22ecbef9b90
diff -r 000000000000 -r 7023c3f98f36 TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Sat Jan 06 17:28:05 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
diff -r 000000000000 -r 7023c3f98f36 data.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data.h	Sat Jan 06 17:28:05 2018 +0000
@@ -0,0 +1,166 @@
+#include "mbed.h"
+#include "BMP280.h"
+#include "date.h"
+float tempf;
+float pressuref;
+float lvl;
+float data_temp [120], data_press[120], data_light[120];
+BMP280 bmp(D14,D15,0x76);
+
+AnalogIn LDR(A0);
+int counterw = 0, full = 0, day, month, year, leap;
+
+void time_rule()
+{
+    if (ss == 10)
+    { 
+        ss = 0;
+        s++;
+    }
+    
+    if (s == 6 && ss == 0)
+    {
+        ss = 1;
+        s = 0;
+        mmi++;
+    }
+    
+    if (mmi == 10)
+    {
+        mmi = 0;
+        mi++;
+    }
+    
+    if (mi == 6 && mmi == 0)
+    {
+        mi = 0;
+        mmi = 1;
+        hh++;    
+    }
+    
+    if (hh == 10)
+    {
+        hh = 0;
+        h++;
+    }
+    
+    if(h == 2 && hh == 4)
+    {
+        h = 0;
+        hh = 0;
+        dd++;
+    }
+}
+
+
+void date_rule()
+{
+   if (mm == 10)
+    {
+        mm = 0;
+        m++;
+    }
+    
+    if (m == 1 && mm == 3)
+    {
+        m = 0;
+        mm = 1;
+        yyyy++;
+    }
+    
+    if (yyyy== 10)
+    {
+        yyyy = 0;
+        yyy++;
+    } 
+    if (yyy == 10)
+    {
+        yyy = 0;
+        yy++;
+    } 
+    if (yy == 10)
+    {
+        yy = 0;
+        y++;
+    } 
+    
+}
+
+
+void day_check()
+{
+    day = 10*d + dd;
+    month = mi*10+mmi;
+    year = y*1000+yy*100+yyy*10+yyyy;
+    if(month == 1||3||5||7||8||10||12)
+    {
+        if (day == 32)
+        {
+            mm++;
+            d = 0;
+            dd = 1;
+        } 
+    }
+
+    else if(month == 4||6||9||11 )
+    {
+        if (day == 31)
+        {
+            mm++;
+            d = 0;
+            dd = 1;
+        }
+    }
+    
+    else if(month == 2)
+    {
+        leap = year % 4;
+        if(leap == 0)
+        {
+            if (day == 30)
+            {
+                mm++;
+                d = 0;
+                dd = 1;
+            }
+        }
+        else 
+        {
+            if (day == 29)
+            {
+                mm++;
+                d = 0;
+                dd = 1;
+            }
+        }
+    }
+    date_rule();
+}
+
+
+
+
+void getdata()
+{
+    tempf = bmp.getTemperature();
+    //tempf = tempf*-1;
+    pressuref = bmp.getPressure();
+    lvl = LDR;
+}
+
+void store() 
+{  
+     data_temp[counterw] = tempf;
+     data_press[counterw] = pressuref;
+     data_light[counterw] = lvl;
+     
+     if (counterw == 120)
+     {
+         counterw = 0;
+         full = 1;
+     }
+     counterw++;
+}
+
+
+
diff -r 000000000000 -r 7023c3f98f36 date.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/date.h	Sat Jan 06 17:28:05 2018 +0000
@@ -0,0 +1,334 @@
+#include "mbed.h"
+DigitalIn sw1(PE_12);
+DigitalIn sw2(PE_14);
+int d = 0,dd = 0,m = 0,mm = 0,y = 0,yy = 0,yyy = 0,yyyy = 0, pointer = 0, h = 0, hh = 0, mi = 0, mmi = 0, s = 0, ss = 0;
+TextLCD lcd(D9,D8,D7,D6,D4,D2);
+
+
+
+
+void display_date_time()
+{
+    lcd.locate(0,0);
+    lcd.printf("%i", d);
+    lcd.locate(1,0);
+    lcd.printf("%i", dd);
+    lcd.locate(3,0);
+    lcd.printf("%i", m);
+    lcd.locate(4,0);
+    lcd.printf("%i", mm);
+    lcd.locate(6,0);
+    lcd.printf("%i", y);
+    lcd.locate(7,0);
+    lcd.printf("%i", yy);
+    lcd.locate(8,0);
+    lcd.printf("%i", yyy);
+    lcd.locate(9,0);
+    lcd.printf("%i", yyyy);  
+    lcd.locate(0,1);
+    lcd.printf("%i", h);
+    lcd.locate(1,1);
+    lcd.printf("%i", hh);
+    lcd.locate(3,1);
+    lcd.printf("%i", mi);
+    lcd.locate(4,1);
+    lcd.printf("%i", mmi);
+    lcd.locate(6,1);
+    lcd.printf("%i", s);
+    lcd.locate(7,1);
+    lcd.printf("%i", ss);
+} 
+
+void display_time()
+{
+    lcd.locate(0,1);
+    lcd.printf("%i", h);
+    lcd.locate(1,1);
+    lcd.printf("%i", hh);
+    lcd.locate(2,1);
+    lcd.printf(":");
+    lcd.locate(3,1);
+    lcd.printf("%i", mi);
+    lcd.locate(4,1);
+    lcd.printf("%i", mmi);
+    lcd.locate(5,1);
+    lcd.printf(":");
+    lcd.locate(6,1);
+    lcd.printf("%i", s);
+    lcd.locate(7,1);
+    lcd.printf("%i", ss);
+} 
+
+void display_dates()
+{
+    lcd.locate(0,0);
+    lcd.printf("%i", d);
+    lcd.locate(1,0);
+    lcd.printf("%i", dd);
+    lcd.locate(2,0);
+    lcd.printf(":");
+    lcd.locate(3,0);
+    lcd.printf("%i", m);
+    lcd.locate(4,0);
+    lcd.printf("%i", mm);
+    lcd.locate(5,0);
+    lcd.printf(":");
+    lcd.locate(6,0);
+    lcd.printf("%i", y);
+    lcd.locate(7,0);
+    lcd.printf("%i", yy);
+    lcd.locate(8,0);
+    lcd.printf("%i", yyy);
+    lcd.locate(9,0);
+    lcd.printf("%i", yyyy);
+}   
+
+
+void update_date_and_time()
+{
+    if (pointer == 0)
+    {
+        lcd.locate(0,0);
+        lcd.printf("%i", d);
+    }
+    
+    if (pointer == 1)
+    {
+        lcd.locate(1,0);
+        lcd.printf("%i", dd);
+    }
+    
+    if (pointer == 2)
+    {
+        lcd.locate(3,0);
+        lcd.printf("%i", m);
+    }
+    
+    if (pointer == 3)
+    {
+        lcd.locate(4,0);
+        lcd.printf("%i", mm);
+    }
+    
+    if (pointer == 4)
+    {
+        lcd.locate(6,0);
+        lcd.printf("%i", y);
+    }
+    
+    if (pointer == 5)
+    {
+        lcd.locate(7,0);
+        lcd.printf("%i", yy);
+    }
+    if (pointer == 6)
+    {
+        lcd.locate(8,0);
+        lcd.printf("%i", yyy);
+    }
+    
+    if (pointer == 7)
+    {
+        lcd.locate(9,0);
+        lcd.printf("%i", yyyy);
+    }  
+    if (pointer == 8)
+    {
+        lcd.locate(0,1);
+        lcd.printf("%i", h);
+    }
+    if (pointer == 9)
+    {
+        lcd.locate(1,1);
+        lcd.printf("%i", hh);
+    }
+    
+    if (pointer == 10)
+    {
+        lcd.locate(3,1);
+        lcd.printf("%i", mi);
+    } 
+    if (pointer == 11)
+    {
+        lcd.locate(4,1);
+        lcd.printf("%i", mmi);
+    }
+    if (pointer == 12)
+    {
+        lcd.locate(6,1);
+        lcd.printf("%i", s);
+    }
+    
+    if (pointer == 13)
+    {
+        lcd.locate(7,1);
+        lcd.printf("%i", ss);
+    } 
+} 
+
+void select_date()
+{
+     if (sw2 == 1)
+     {
+         wait (1);
+         pointer++;
+     }
+     else if(pointer != 14)
+     {
+        switch (pointer)
+        {
+        case 0: 
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    d++;
+                    if (d == 4)
+                    {
+                        d = 0;
+                    }
+                }
+        case 1: 
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    dd++;
+                    if (dd == 10)
+                    {
+                        dd = 0;
+                    }
+                }
+        case 2: 
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    m++;
+                    if (m == 2)
+                    {
+                        m = 0;
+                    }
+                }
+        case 3: 
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    mm++;
+                    if (mm == 10)
+                    {
+                        mm = 0;
+                    }
+                }
+        case 4: 
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    y++;
+                    if (y == 3)
+                    {
+                        y = 0;
+                    }
+                }
+        case 5: 
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    yy++;
+                    if (yy == 10)
+                    {
+                        yy = 0;
+                    }
+                }
+        case 6: 
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    yyy++;
+                    if (yyy == 10)
+                    {
+                        yyy = 0;
+                    }
+                }
+        case 7: 
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    yyyy++;
+                    if (yyyy == 10)
+                    {
+                        yyyy = 0;
+                    }
+                }
+        case 8:
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    h++;
+                    if (h== 3)
+                    {
+                        h = 0;
+                    }
+                }
+        case 9:
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    hh++;
+                    if (hh == 10)
+                    {
+                        hh = 0;
+                    }
+                }
+        case 10:
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    mi++;
+                    if (mi == 6)
+                    {
+                        mi = 0;
+                    }
+                }
+        case 11:
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    mmi++;
+                    if (mmi == 10)
+                    {
+                        mmi = 0;
+                    }
+                }
+        case 12:
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    s++;
+                    if (s == 6)
+                    {
+                        s = 0;
+                    }
+                }
+        case 13:
+            if (sw1 == 1)
+                {
+                    wait (1);
+                    ss++;
+                    if (ss == 10)
+                    {
+                        ss = 0;
+                    }
+                }
+        
+        
+        
+        }
+    }
+update_date_and_time();
+}
+
+
+
+
+       
+       
+            
+            
\ No newline at end of file
diff -r 000000000000 -r 7023c3f98f36 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jan 06 17:28:05 2018 +0000
@@ -0,0 +1,85 @@
+#include "mbed.h"
+#include "TextLCD.h"
+#include "BMP280.h"
+#include "putty.h"
+//DigitalOut myled(LED1);
+int dislcd = 0;
+float T = 15;
+Ticker display;
+Ticker second_pass;
+InterruptIn button(USER_BUTTON);
+
+//NVIC_SetPriority(display, 0);     
+//NVIC_SetPriority(second_pass, 1);
+//NVIC_SetPriority(button, 1);
+void second_tick()
+{
+    ss++;
+    time_rule();   
+    day_check();
+    lcd.cls();
+    if (dislcd == 1)
+    {
+        lcd.locate(10,0);
+        lcd.printf("l:%1.2f", lvl);
+        lcd.locate(0,0);
+        lcd.printf("p:%3.1f", pressuref);
+        lcd.locate(10,1);
+        lcd.printf("t:%3.1f", tempf);
+        display_time();
+    }
+    
+    else if (dislcd == 0)
+    {
+        display_dates();
+        display_time();
+    }
+}
+
+void lcddisp()
+{ 
+    display_time();
+    getdata();
+    store();
+}
+
+void check_display()
+{ 
+    if(dislcd == 0)
+    {dislcd = 1;}
+    else
+    {dislcd = 0;}
+}
+
+
+int main()
+{
+    lcd.cls();
+    //display_date_time();
+//    while (pointer != 14)
+//    {
+//        select_date();
+//    }
+    bmp.initialize();
+    pc.printf("putty ready\n\r");
+    display.attach(&lcddisp, T);
+    second_pass.attach(&second_tick, 1.0);
+    button.rise(&check_display);
+    
+    
+    while(1)
+    {
+            check_display();
+            putty_write();
+            if (interrupt == 1);
+            {
+                T = t;
+                display.attach(&lcddisp, T);
+                interrupt =0;
+            }
+            check_display();
+    }
+}
+    
+    
+    
diff -r 000000000000 -r 7023c3f98f36 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jan 06 17:28:05 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7130f322cb7e
\ No newline at end of file
diff -r 000000000000 -r 7023c3f98f36 putty.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/putty.h	Sat Jan 06 17:28:05 2018 +0000
@@ -0,0 +1,270 @@
+#include "mbed.h"
+#include "data.h"
+Serial pc(USBTX, USBRX); 
+char user_command[40] = {0};
+char user_command2[40] = {0};
+int n, datan = 0, datac = 0, counterd = 0, dates, times, interrupt = 0;
+float t;
+
+
+void readall()
+{
+    datan = counterw;
+    pc.printf("readall selected\n\r");
+    if (full == 1)
+        {
+            datac = 120;
+        }
+    else
+        {
+            datac = counterw;
+        }
+    pc.printf("printting %i datas\n\r", datac);
+    while (counterd < datac)  
+        { 
+            pc.printf("light: %2.4f, temp: %3.4f, press: %3.4f\n\r", data_light[datan], data_temp [datan], data_press[datan]);  
+            if (datan == 0)
+                {
+                    datan = 121;
+                }
+            datan--;
+            counterd++;     
+        }
+    counterd = 0;
+}
+
+void readn()
+{
+    
+    counterd = 0; 
+    n = atoi(user_command2);
+    pc.printf("read %i datas\n\r",n);
+    if (n > counterw)
+        {
+            pc.printf("we only have %i datas \n\r", counterw);
+        }
+    else
+        {
+            while (counterd < n)  
+                { 
+                    pc.printf("light: %2.4f, temp: %3.4f, press: %3.4f\n\r",data_light[datan], data_temp [datan], data_press[datan]);  
+                    if (datan == 0)
+                        {
+                            datan = 121;
+                        }
+                    datan--;
+                    counterd++;     
+                }  
+         }   
+}
+
+void deleteall()
+{
+    pc.printf("deleted %i datas \n\r", counterw);
+    counterw = 0;
+    int counter = 0;
+    while (counter < 121)
+        {
+            data_light[counter] = 0;
+            data_temp [counter] = 0; 
+            data_press[counter] = 0; 
+            counter ++;
+            full = 0;
+        }  
+}
+
+void deleten()
+{
+    datan = counterw;
+    counterd = 0;
+    n = atoi(user_command2);
+    if (n > counterw && full == 0)
+    {
+        pc.printf("we only have %i datas \n\r", counterw);
+    }
+    else if(full == 1 && n> 120)
+    {
+        pc.printf("we only have 120 datas \n\r");
+    }
+    else if(full == 0 && n < counterw)
+        {
+            pc.printf("deleted %i datas \n\r", n);
+            counterw = counterw-n;
+            while (counterd < n)
+                {
+                    data_light[datan] = 0;
+                    data_temp [datan] = 0; 
+                    data_press[datan] = 0; 
+                    counterd ++;
+                    datan--;
+                }
+        }
+   else if(full == 1 && n < 120)
+        {
+            pc.printf("deleted %i datas \n\r", n);
+            counterw = counterw-n;
+            while (counterd < 120)
+                {
+                    data_light[datan] = 0;
+                    data_temp [datan] = 0; 
+                    data_press[datan] = 0; 
+                    counterd ++;
+                    datan--;
+                }
+        } 
+}
+//void fill(char c[20], char c2[20])
+//{
+//    int counterino = 0;
+//    while (counterino <21)
+//    {
+//    user_command[counterino] = c[counterino];
+//    user_command2[counterino] = c2[counterino];
+//    counterino++;
+//    }
+      
+//}
+void clear()
+{
+    int counter = 0;
+    while (counter < 40)
+   {
+        user_command[counter] = 0;
+        counter ++;
+    }
+}
+
+
+void clear2()
+{
+    int counter = 0;
+    while (counter < 40)
+    {
+        user_command2[counter] = 0;
+        counter ++;
+    }
+}
+
+void selection()
+{
+    counterd = 0;
+    datan = counterw-1;
+    if (user_command[0] == 'R'&& user_command[1] == 'E'&& user_command[2] == 'A'&& user_command[3] == 'D')
+    {
+        if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L')
+        {
+            readall();
+          }
+        
+        else
+        {
+            readn();
+        }
+    }   
+    
+    else if (user_command[0] == 'D'&& user_command[1] == 'E'&& user_command[2] == 'L'&& user_command[3] == 'E' && user_command[4] == 'T' && user_command[5] == 'E')
+    {
+        if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L')
+        {
+            pc.printf("deleteall selected\n\r");
+            deleteall();
+        }
+    
+         else
+        {
+            n = atoi(user_command2);
+            pc.printf("delete %i\n\r",n);
+            deleten();
+         }
+    }
+    
+    else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'D' && user_command[4] == 'A' && user_command[5] == 'T' && user_command[6] == 'E')
+    {
+          dates = atoi(user_command2); 
+          yyyy =  dates%10;
+          dates /= 10;
+          yyy = dates%10;
+          dates /= 10; 
+          yy = dates%10;
+          dates /= 10;
+          y = dates%10;
+          dates /= 10;
+          mm = dates%10;
+          dates /= 10;
+          m = dates%10;
+          dates /= 10;
+          dd = dates%10;
+          dates /= 10;
+          d = dates%10;
+          pc.printf("you set the date to %i%i/%i%i/%i%i%i%i\n\r", d,dd,m,mm,y,yy,yyy,yyyy);
+    }
+    else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'T' && user_command[4] == 'I' && user_command[5] == 'M' && user_command[6] == 'E')
+    {
+          times = atoi(user_command2); 
+          ss =  times%10;
+          times /= 10;
+          s = times%10;
+          times /= 10; 
+          mmi = times%10;
+          times /= 10;
+          mi = times%10;
+          times /= 10;
+          hh = times%10;
+          times /= 10;
+          h = times%10;
+          pc.printf("you set the time to %i%i:%i%i:%i%i\n\r", h,hh,mi,mmi,s,ss);
+    }
+    else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'T')
+    {
+        t = atof(user_command2);
+        pc.printf("you set the period to %2.2f", t);
+        interrupt = 1;
+    }
+}
+//int main()
+//{
+//    pc.printf("putty ready\n\r");
+//    while(1)
+//        {
+//            clear();
+//            clear2();
+//            while (user_command[0] == 0)
+//                {
+//                     pc.scanf("%s",user_command);
+//                     pc.scanf("%s",user_command2);
+//                     pc.printf("you typed: %s %s\n\r",user_command,user_command2);
+//                }
+//                
+//                selection();
+//         }
+//}
+
+
+void putty_write ()
+{
+    int count = 0;
+            int wcount = 0;
+            while (user_command[wcount]!= ' ')
+            {
+                user_command[count] = pc.getc();
+                pc.putc(user_command[count]);
+                count++;
+                wcount = count -1;
+            }
+            int count2 = 0;
+            int wcount2 = 0;
+            while(user_command2[wcount2]!= '\r')
+            {
+                user_command2[count2] = pc.getc();
+                pc.putc(user_command2[count2]);
+                count2++;
+                wcount2 = count2 -1;
+            }
+            
+            
+            pc.printf("you typed: %s %s\n\r",user_command,user_command2);
+            selection();
+            clear();
+            clear2();  
+            
+}
\ No newline at end of file