testfase

Dependencies:   TextLCD mbed DS1307 Servo

Files at this revision

API Documentation at this revision

Comitter:
JonathanCaes
Date:
Thu Dec 04 09:45:59 2014 +0000
Parent:
0:09e0c8d681a8
Commit message:
Test Programma 4/12/2014

Changed in this revision

DS1307.lib Show annotated file Show diff for this revision Revisions of this file
Servo.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1307.lib	Thu Dec 04 09:45:59 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/harrypowers/code/DS1307/#c3e4da8feb10
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Thu Dec 04 09:45:59 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- a/main.cpp	Thu Nov 27 10:09:27 2014 +0000
+++ b/main.cpp	Thu Dec 04 09:45:59 2014 +0000
@@ -1,6 +1,8 @@
 //Library's
 #include "mbed.h"
 #include "TextLCD.h"
+#include "Servo.h"
+#include "ds1307.h"
 
 //Pin initialisatie
 Serial pc(USBTX,USBRX);
@@ -15,17 +17,70 @@
 DigitalOut myled3(LED3);
 TextLCD lcd(p15, p16, p21, p22, p23, p24); // rs, e, d4-d7
 PwmOut Servo(p25);
+DS1307 my1307(p9, p10);
+DigitalOut relais1(p30);
+DigitalOut RGBblauw(p29);
+DigitalOut RGBgroen(p28);
+DigitalOut RGBrood(p27);
 
 //variabelen declareren/initialiseren
 float i = 0;
 float j = 0;
-int temperatuur = 20;
-int counter = 0;
+int temperatuur = 23;
+int counter = 49;
+int counter2 = 249;
 int teller = 0;
+int RTC = 0;
+int motor = 2; //motor = 2, dan is hij in ruststand
+
+//variabelen RTC
+ int sec;
+ int min;
+ int hours;
+ int day;
+ int date;
+ int month;
+ int year;
+ 
+ void test_rw(int test) {
+} 
 
 //Main Programma
 int main()
 {
+    Servo.period_ms(20);
+    Servo = (90 * 0.000511 + 0.026); // rust
+    wait(0.1);
+    if((i*3.3)>= temperatuur)// te warm
+    {
+        motor = 0;
+        myled1 = 1;
+        relais1 = 0;    //Relais aansturen
+        RGBrood = 1;    //RGB aansturen
+        RGBgroen = 0;
+        RGBblauw = 0; 
+        if(motor == 0 || motor == 2)//motor = 0, dan staat hij links
+        { 
+            Servo.period_ms(20);
+            Servo = (170 * 0.000511 + 0.026); // rechts
+            motor = 1;
+        }  
+    }
+    if((i*3.3) < temperatuur)// te koud
+    {
+        motor = 1;
+        myled1 = 0;
+        relais1 = 1;    //Relais aansturen
+        RGBrood = 0;    //RGB aansturen
+        RGBgroen = 1;
+        RGBblauw = 1;
+        if(motor == 1 || motor == 2) //motor = 1, dan staat hij rechts
+        {
+            Servo.period_ms(20); 
+            Servo = (1 * 0.000511 + 0.026); // links
+            motor = 0;
+        }
+    }
     pc.printf("\x1B\x48\x1B\x4A");
     pc.printf("Temperatuur");
     while(1)
@@ -48,9 +103,9 @@
         }
 /*------------------------------------------------------------------------*/
         //Motor aansturen
-        Servo.period_ms(20);
-        if(knopUP)
+        /*if(knopUP)
         {
+            Servo.period_ms(20);
             Servo = (90 * 0.000511 + 0.026); // rust
             wait(1);
             Servo = (7 * 0.000511 + 0.026); // links 7
@@ -59,7 +114,7 @@
             wait(1);
             Servo = (170 * 0.000511 + 0.026); // rechts
             wait(1);
-        }
+        }*/
 /*------------------------------------------------------------------------*/
         //Menu Instellingen
         if(knopINSTEL)
@@ -83,14 +138,8 @@
                     if(temperatuur < 20)
                     {
                         temperatuur = 30;   
-                    } 
-                    lcd.cls();
-                    lcd.locate(0,0);
-                    lcd.printf("Ingestelde Temp");
-                    lcd.locate(0,1);
-                    lcd.printf("       %iC     ", temperatuur);
-                    wait(0.6);
-                    lcd.cls();
+                    }
+                    wait(0.2); 
                 }
                 if(knopDOWN)
                 {
@@ -103,56 +152,202 @@
                     {
                         temperatuur = 30;   
                     } 
+                    wait(0.2);
+                    /*
                     lcd.cls();
                     lcd.locate(0,0);
                     lcd.printf("Ingestelde Temp");
                     lcd.locate(0,1);
                     lcd.printf("       %iC     ", temperatuur);
                     wait(0.6);
-                    lcd.cls();
+                    lcd.cls();*/
                 }
             }
+            wait(0.5);
         }
 /*------------------------------------------------------------------------*/
-        //Temperatuur instellen
-        /*if(knopUP)
-        {
-            temperatuur = temperatuur + 1;
-            if(temperatuur == 30)
-            {
-                temperatuur = 24;  
-            }    
-            lcd.cls();
-            lcd.locate(0,0);
-            lcd.printf("ingestelde temp");
-            lcd.locate(0,1);
-            lcd.printf("       %iC     ", temperatuur);
-            wait(1);
-        }*/
-/*------------------------------------------------------------------------*/
         /*Temperatuur: Wanneer temperatuur hoger wordt dan ingesteld
-                       zal een ledje dit aangeven*/
-        if((i*3.3)>= temperatuur)
+                       zal een ledje dit aangeven
+          Relais aansturen
+          RGB led aansturen
+          Servomotor aansturen
+        */        
+        if((i*3.3)>= temperatuur + 1)// te warm
+        {
+            myled1 = 1;
+            relais1 = 0;    //Relais aansturen
+            RGBrood = 1;    //RGB aansturen
+            RGBgroen = 0;
+            RGBblauw = 0; 
+            if(motor == 0)//motor = 0, dan staat hij links
+            { 
+                Servo.period_ms(20);
+                Servo = (170 * 0.000511 + 0.026); // rechts
+                motor = 1;
+            }  
+        }
+        if((i*3.3) <= temperatuur - 1)// te koud
         {
-            myled1 = 1;    
+            myled1 = 0;
+            relais1 = 1;    //Relais aansturen
+            RGBrood = 0;    //RGB aansturen
+            RGBgroen = 1;
+            RGBblauw = 1;
+            if(motor == 1) //motor = 1, dan staat hij rechts
+            {
+                Servo.period_ms(20); 
+                Servo = (1 * 0.000511 + 0.026); // links
+                motor = 0;
+            }
         }
-        if((i*3.3) < temperatuur)
+/*------------------------------------------------------------------------*/    
+        //LCD Display uitschrijven RTC of Temperatuur
+        if(knopBACK)
+        {
+            RTC ++;
+            if(RTC == 2)
+            {
+                RTC = 0;    
+            }
+            wait(0.5);    
+        }
+        if(RTC == 0)
         {
-            myled1 = 0;    
+            //LCD uitschrijven
+            counter++;
+            if(counter == 50)
+            {
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Temp 1:%4.1fC", i*3.3);
+                lcd.locate(0,1);
+                lcd.printf("Temp 2:%4.1fC", j*3.3);
+                pc.printf("\n\n\rTemperature1 %4.1f C ",i*3.3);
+                pc.printf("\n\rTemperature2 %4.1f C ",j*3.3);
+                counter = 0;
+            }
         }
-/*------------------------------------------------------------------------*/
-        //LCD uitschrijven
-        counter++;
-        if(counter == 250)
-        {
-            lcd.cls();
-            lcd.locate(0,0);
-            lcd.printf("Temp 1:%4.1fC", i*3.3);
-            lcd.locate(0,1);
-            lcd.printf("Temp 2:%4.1fC", j*3.3);
-            pc.printf("\n\n\rTemperature1 %4.1f C ",i*3.3);
-            pc.printf("\n\rTemperature2 %4.1f C ",j*3.3);
-            counter = 0;
+        else if(RTC == 1)
+        {   
+            //RTC uitschrijven
+            counter2++;
+            if(counter2 == 250)
+            {
+                lcd.cls();
+                test_rw(my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year));
+                //Dag uitschrijven op lcd
+                if(day == 1)
+                {lcd.locate(3,1);
+                lcd.printf("Ma");}
+                if(day == 2)
+                {lcd.locate(3,1);
+                lcd.printf("Di");}
+                if(day == 3)
+                {lcd.locate(3,1);
+                lcd.printf("Wo");}
+                if(day == 4)
+                {lcd.locate(3,1);
+                lcd.printf("Do");}
+                if(day == 5)
+                {lcd.locate(3,1);
+                lcd.printf("Vr");}
+                if(day == 6)
+                {lcd.locate(3,1);
+                lcd.printf("Za");}
+                if(day == 7)
+                {lcd.locate(3,1);
+                lcd.printf("Zo");}
+                //Uur min sec //Dag datum maand jaar
+                if(sec >= 9 && min >= 9 && hours >= 9)
+                {
+                    lcd.locate(4,0);
+                    lcd.printf("%d:%d:%d",hours,min,sec);
+                    lcd.locate(6,1);
+                    lcd.printf("%d/%d/%d",date,month,year);
+                    if(knopBACK)
+                    {
+                        RTC = 0;    
+                    }
+                }
+                if(sec <= 9 && min >= 9 && hours >= 9)
+                {
+                    lcd.locate(4,0);
+                    lcd.printf("%d:%d:0%d",hours,min,sec);
+                    lcd.locate(6,1);
+                    lcd.printf("%d/%d/%d",date,month,year);
+                    if(knopBACK)
+                    {
+                        RTC = 0;    
+                    }
+                }
+                if(sec >= 9 && min <= 9 && hours >= 9)
+                {
+                    lcd.locate(4,0);
+                    lcd.printf("%d:0%d:%d",hours,min,sec);
+                    lcd.locate(6,1);
+                    lcd.printf("%d/%d/%d",date,month,year);
+                    if(knopBACK)
+                    {
+                        RTC = 0;    
+                    }
+                }
+                if(sec >= 9 && min >= 9 && hours <= 9)
+                {
+                    lcd.locate(4,0);
+                    lcd.printf("0%d:%d:%d",hours,min,sec);
+                    lcd.locate(6,1);
+                    lcd.printf("%d/%d/%d",date,month,year);
+                    if(knopBACK)
+                    {
+                        RTC = 0;    
+                    }
+                }
+                if(sec <= 9 && min <= 9 && hours >= 9)
+                {
+                    lcd.locate(4,0);
+                    lcd.printf("%d:0%d:0%d",hours,min,sec);
+                    lcd.locate(6,1);
+                    lcd.printf("%d/%d/%d",date,month,year);
+                    if(knopBACK)
+                    {
+                        RTC = 0;    
+                    }
+                }
+                if(sec <= 9 && min >= 9 && hours <= 9)
+                {
+                    lcd.locate(4,0);
+                    lcd.printf("0%d:%d:0%d",hours,min,sec);
+                    lcd.locate(6,1);
+                    lcd.printf("%d/%d/%d",date,month,year);
+                    if(knopBACK)
+                    {
+                        RTC = 0;    
+                    }
+                }
+                if(sec >= 9 && min <= 9 && hours <= 9)
+                {
+                    lcd.locate(4,0);
+                    lcd.printf("0%d:0%d:%d",hours,min,sec);
+                    lcd.locate(6,1);
+                    lcd.printf("%d/%d/%d",date,month,year);
+                    if(knopBACK)
+                    {
+                        RTC = 0;    
+                    }
+                }
+                if(sec <= 9 && min <= 9 && hours <= 9)
+                {
+                    lcd.locate(4,0);
+                    lcd.printf("0%d:0%d:0%d",hours,min,sec);
+                    lcd.locate(6,1);
+                    lcd.printf("%d/%d/%d",date,month,year);
+                    if(knopBACK)
+                    {
+                        RTC = 0;    
+                    }
+                }
+                counter2 = 0;
+            }
         }
     }
 }
\ No newline at end of file