pp

Dependencies:   mbed

Revision:
3:dc88b52d526c
Parent:
2:6b4dda997dc0
Child:
4:a61cdd4e7afa
--- a/main.cpp	Sat Dec 05 14:32:27 2015 +0000
+++ b/main.cpp	Sat Dec 05 16:43:40 2015 +0000
@@ -7,15 +7,24 @@
 DigitalOut buzzer(D6);
 BusIn b(D9,D10,D11);
 BusOut led(D2,D3,D4,D5);
+AnalogIn analog_value(A2);
+
+void DisplayTime();
+
 int mode=0;
 int main() 
 {
    b.mode(PullUp);
-   int n=0;
-   // DisplayTime();
-   display.Displayset(0x77,5,5,5);
+   int sec=45,min=59,hour=6,day=7,date=5,month=12,year=15;
+   int n=0,opt=1,p=0,ten_hour,nu_hour,ten_min,nu_min,hour_a=7,min_a=0;
+   float mea;
+        
+   myrtc.settime(sec,min,hour,day,date,month,year);
+   //DisplayTime();
+   //display.Displayset((hour-(hour%10))/10,hour%10,(min-(min%10))/10,min%10);
    while(1)
-   {
+   {        
+        mea=analog_value.read();
         if(b==0b011){n=1;}
         else if(b==0b101){n=2;}
         else if(b==0b110){n=3;}
@@ -30,39 +39,43 @@
         //printf("%d\n",mode);
         
         wait_ms(100);
-   }
-}
-
-void DisplayTime()
-{
-    int sec=0,min=35,hour=15,day=7,date=5,month=12,year=15;
-    int a_hour=15,a_min=36;
-    
-    myrtc.settime(sec,min,hour,day,date,month,year);
-  
-    printf("time set : %d:%d:%d      day : %d     date set : %d:%d:%d\n  ",hour,min,sec,day,date,month,year);
-    
-    while(1) {
+        
+        if(display.checkButton3()==1)
+        {
+            p++;
+            if(p==10){p=0;}
+            printf("%d\n",p);
+            if(p%2==0){opt=1;}
+            if(p%2==1){opt=2;}
+        }
+        
         myrtc.gettime(&sec,&min,&hour,&day,&date,&month,&year);
-        printf("time read : %d:%d:%d      day : %d     date read : %d:%d:%d\n  ",hour,min,sec,day,date,month,year);
-        
-        display.setColon(1);
         
-        if(((hour-(hour%10))/10)>0)
+        if(opt==1)
         {
-            display.write(0, (hour-(hour%10))/10);     
-            display.write(1, hour%10);    
-            display.write(2, (min-(min%10))/10);    
-            display.write(3, min%10);
+            display.setColon(1);
+                 display.Displayset((hour-(hour%10))/10,hour%10,(min-(min%10))/10,min%10);           
         }
-        else if(((hour-(hour%10))/10)==0 )
-        {     
-            display.write(0, 0xFF);
-            display.write(1, hour%10);    
-            display.write(2, (min-(min%10))/10);    
-            display.write(3, min%10);
-        }  
-        if(hour==a_hour && min==a_min){buzzer=1;wait(2);buzzer=0;}
+        if(opt==2)
+        {
+             ten_hour=(hour_a-(hour_a%10))/10;
+             nu_hour=hour_a%10;
+             ten_min=(min_a-(min_a%10))/10;
+             nu_min=min_a%10;
+             display.Displayset(ten_hour,nu_hour,ten_min,nu_min);
         
-    }
-}
+             if(display.checkButton1()==1){hour_a++;}
+             if(display.checkButton2()==1){min_a++;}
+             
+             if(hour_a==24){hour_a=0;}
+             if(min_a==60){min_a=0;}
+             
+        }
+        if(hour==hour_a&&min==min_a){buzzer=1;}
+        else{buzzer=0;}
+        
+        printf("%f\n",mea);
+        if(mea>=0.65){min_a=min_a+1;}
+        
+   }
+}
\ No newline at end of file