Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed C12832_lcd
Diff: main.cpp
- Revision:
- 1:13aae0117bbf
- Parent:
- 0:275c29641333
- Child:
- 2:684c698024c4
--- a/main.cpp Fri Nov 09 16:44:37 2018 +0000
+++ b/main.cpp Thu Nov 15 12:01:57 2018 +0000
@@ -4,29 +4,97 @@
C12832_LCD lcd;
Timeout increment;
-
- int hours=0;
- int minutes=0;
-
- void adj_min() {
- if (minutes>59) {
-hours++;
-minutes=0;
+BusIn up(p16);
+BusIn down(p17);
+BusIn left(p18);
+BusIn right(p19);
+BusIn centre(p20);
+
+int hours=0;
+int minutes=0;
+bool toggle=false;
+
+// How to detect if up is hold not press?
+
+if (up = 1){
+ if (left = 1) {
+ inc_hrs();
+ }
+ else if (right = 1){
+ inc_min();
+ }
+ }
+
+
+if (down = 1)
+{
+ if (left = 1) {
+ inc_hrs();
+ } else if (right=1) {
+ inc_min();
+ }
+}
+/**
+ Adjust minutes
+*/
+void adj_min()
+{
+ if (minutes>59) {
+ minutes=0;
+ } else if (minutes<59) {
+ minutes=0;
+ )
+}
+/**
+ adj hrs
+*/
+void adj_hrs()
+{
+ if (hours>23) {
+ hours=0;
+ }
+ else if (hours<23) {
+ hours=0;
+ )
+}
+
+/**
+ Increment minutes
+*/
+void inc_min()
+{
+ minutes++;
+ adj_min();
+
+}
+void inc_hrs()
+{
+ hours++;
+ adj_hrs();
+
+}
+
+/**
+ Main entry point
+*/
+int main()
+{
+ while(true) {
+ increment.attach(&inc_min, 60.0);
+ }
+
+ lcd.cls();
+ lcd.locate(0,15);
+
+// Check if minutes are less than 10 so a 0 can be prefixed onto the display
+ string mins = "00"; // String to display in lcd screen
+
+ if(minutes < 10) {
+ mins = "0" + minutes;
+ } else {
+ mins = minutes;
+ }
+ lcd.printf("%s", mins);
+
}
}
-void inc_min() {
-minutes++;
-adj_min() ;
-
-if (hours>23) {
- hours = 0;
- }
-}
-int main() {
- while(true) {
- increment.attach(&inc_min, 60.0);
- }
- lcd.cls();
- lcd.locate(0,15);
- lcd.printf("%d", minutes);
-}