AirsoftTimer software based on mbed

Dependencies:   mbed TextLCD keypad

Revision:
3:ce34dfe2463b
Parent:
2:f8e46daca111
Child:
4:2c91c9eccf3a
--- a/main.cpp	Tue Feb 26 19:04:20 2013 +0000
+++ b/main.cpp	Fri Dec 12 20:07:28 2014 +0000
@@ -7,8 +7,8 @@
 
 
 struct product {
-  int weight;
-  float price;
+    int weight;
+    float price;
 } ;
 
 
@@ -18,14 +18,7 @@
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 
-/*DigitalOut rs(P1_30);
-DigitalOut e(P1_31);
-DigitalOut d4(P0_23);
-DigitalOut d5(P0_24);
-DigitalOut d6(P0_25);
-DigitalOut d7(P0_26);*/
-
-DigitalOut buzzer(P2_3);
+PwmOut buzzer(P2_3);
 
 DigitalOut leda(P2_4);
 DigitalOut ledb(P2_5);
@@ -47,21 +40,20 @@
 //keyboardRowPins = {P0_8 , P0_9 , P0_10, P0_11};              // ROWS=P0.8 -> P0.11
 //keyboardColPins = {P0_16, P0_17, P0_18};                     // COLS=P0.16 -> P0.18
 
-void beep(){
-    buzzer = 1;
-    wait(0.02);
-    buzzer = 0;
-}
-
-void heartbeatThread(void const *args){
-    while(true){
+void heartbeatThread(void const *args)
+{
+    while(true) {
         heartbeatLed = 1;
+        leda = ledb = 1;
         osDelay(10);
         heartbeatLed = 0;
+        leda = ledb = 0;
         osDelay(300);
         heartbeatLed = 1;
+        leda = ledb = 1;
         osDelay(10);
         heartbeatLed = 0;
+        leda = ledb = 0;
         osDelay(680);
     }
 }
@@ -70,58 +62,28 @@
 
 int main()
 {
+    int tone =2300;
     osThreadCreate(osThread(heartbeatThread), NULL);
     TextLCD lcd(P1_30, P1_31, P0_23, P0_24, P0_25, P0_26,  TextLCD::LCD20x4); // rs, e, d4-d7
+    buzzer.period_us(1/2400);
 
     while(1) {
-        //lcd.cls();
-        lcd.locate(0,0);
-        lcd.printf("AirsoftTimer\n");
-        col1 = 1;
-        col2 = 0;
-        col3 = 0;
-        lcd.printf("r1:%d r2:%d r3:%d r4:%d\n", row1.read(), row2.read(), row3.read(), row4.read());
-        lcd.printf("Buzzer:%d Key:%d\n",buzzer.read(), key.read());
-        
-/*        led2 = 1;
-        led3 = 1;
-        led4 = 1;*/
-        //rs = e = d4 = d5 = d6 = d7 = 1;
-        leda = ledb = 1;
-        beep();
-        
-/*        switch(colCounter){
-            case 1:
-                col1=1;
-                col2=0;
-                col3=0;
-            break;
-            case 2:
-                col1=0;
-                col2=1;
-                col3=0;
-            break;
-            case 3:
-                col1=0;
-                col2=0;
-                col3=1;
-            break;
+
+        lcd.locate(0,1);
+        lcd.printf("  - AirsoftTimer - ");
+        lcd.locate(0,3);
+        lcd.printf("Prototype       V0.3");
+
+        tone = tone +20;
+        if(tone > 2500) tone = 2300;
+        if(!button) {
+            buzzer.period_us(1000000/tone);
+            buzzer = 0.5;
+        } else {
+            buzzer = 0.0;
         }
-        
-        colCounter++;
-        if(colCounter > 3) colCounter = 1;*/
-        
-        wait(0.2);
 
-        ///////////////////////
-
-        
-        led2 = 0;
-        led3 = 0;
-        led4 = 0;
-        //rs = e = d4 = d5 = d6 = d7 = 0;
-        leda = ledb = 0;
-        osDelay(200);
+        osDelay(10);
     }
 }