A simple alarm clock for the 1 day workshop presented by Skool and ARM Hungary in 2015.

Dependencies:   Skool_wkshp_lib2015 mbed

Files at this revision

API Documentation at this revision

Comitter:
lvagasi
Date:
Thu Oct 01 19:26:27 2015 +0000
Parent:
3:b82d537ce79c
Commit message:
Complete project for workshop

Changed in this revision

Skool_wkshp_lib2015.lib Show annotated file Show diff for this revision Revisions of this file
mbed_clock.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b82d537ce79c -r 2c4154aae49e Skool_wkshp_lib2015.lib
--- a/Skool_wkshp_lib2015.lib	Fri Sep 25 14:05:41 2015 +0000
+++ b/Skool_wkshp_lib2015.lib	Thu Oct 01 19:26:27 2015 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/lvagasi/code/Skool_wkshp_lib2015/#3ad0af8abf43
+https://developer.mbed.org/users/lvagasi/code/Skool_wkshp_lib2015/#68d1a8c4970b
diff -r b82d537ce79c -r 2c4154aae49e mbed_clock.cpp
--- a/mbed_clock.cpp	Fri Sep 25 14:05:41 2015 +0000
+++ b/mbed_clock.cpp	Thu Oct 01 19:26:27 2015 +0000
@@ -12,6 +12,7 @@
 
 uint32_t Systck_cnt = 0;
 uint32_t Systck_evt = 0;
+uint32_t RGB_sel = 0;
 
 extern uint32_t Index;
 extern uint32_t new_key;
@@ -45,8 +46,33 @@
     Systck_evt++;
 }
 
+void Drive_RGB_LED(void) {
+    switch (RGB_sel % 3) {
+        case 0: 
+            R_LED = 0;
+            G_LED = 1;
+            B_LED = 1;
+            break;
+        case 1: 
+            R_LED = 1;
+            G_LED = 0;
+            B_LED = 1;
+            break;
+        case 2: 
+            R_LED = 1;
+            G_LED = 1;
+            B_LED = 0;
+            break;
+        default: 
+            R_LED = 1;
+            G_LED = 1;
+            B_LED = 1;
+            break;
+    }
+    RGB_sel++;
+}
+
 int main() {
-    uint32_t RGB_sel = 0;
     uint32_t dummy;
     int i;
     float tone;
@@ -66,9 +92,9 @@
 
     init_ser_lcd();
     write_ser_lcd(0x80, false);     // set DDRAM addr to 0x00
-    write_ser_text((char *)"  Alarm  clock  ", 16);
+    write_ser_text((char *)"ARM        SKOOL",16);
     write_ser_lcd(0xC0, false);     // set DDRAM addr to 0x40, beginning of 2nd line
-    write_ser_text((char *)"ARM        SKOOL",16);
+    write_ser_text((char *)"  Alarm  clock  ", 16);
 
     wait(3.0);
 
@@ -84,6 +110,7 @@
             if ((Index < 0xFF) & (Keytable[Index] == '#')) {
                 Main_FSM_States = IN_MENU;
                 MainMenu_Handler();
+                if (Main_FSM_States == FINISH) {Main_FSM_States = IN_LOOP;}
             }
             new_key = 0;
             Index = 0xFF;
@@ -105,6 +132,7 @@
         if (AlarmA_triggered) {
             AlarmA_triggered = 0;
             ShowAlarmText();
+            Drive_RGB_LED();
             for (i = 0; i < 54; i++) {
                 if (song[i][0] > 0.0f) {
                     tone = float(1.0f/scala[song[i][0]]);
@@ -115,11 +143,13 @@
                 }
                 wait(float(1.0f/song[i][1]));
                 if ((new_key != 0) & (Index < 0xFF) & (Keytable[Index] == '#')) {
+                    speaker = 0;
                     i = 54;
                     new_key = 0;
                     Index = 0xFF;
                     HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
                 }
+                Drive_RGB_LED();
             }
             write_ser_lcd(0x01, false);     // Clear display
             wait_us(1100);
@@ -127,39 +157,19 @@
             wait_us(30);
             ShowTime();
             ShowDate();
+            R_LED = 1;
+            G_LED = 1;
+            B_LED = 1;
         }
 
         if (Systck_cnt > 5) {
-            switch (RGB_sel % 3) {
-                case 0: 
-                    R_LED = 0;
-                    G_LED = 1;
-                    B_LED = 1;
-                    break;
-                case 1: 
-                    R_LED = 1;
-                    G_LED = 0;
-                    B_LED = 1;
-                    break;
-                case 2: 
-                    R_LED = 1;
-                    G_LED = 1;
-                    B_LED = 0;
-                    break;
-                default: 
-                    R_LED = 1;
-                    G_LED = 1;
-                    B_LED = 1;
-                    break;
-            }
-            RGB_sel++;
             Systck_cnt = 0;
         }
         //HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
-        //__WFI();
-        while (Systck_evt == 0) {
-            dummy++;
-        }
+        __WFI();
+        //while (Systck_evt == 0) {
+        //    dummy++;
+        //}
         Systck_evt = 0;
     }
 }