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:
- 3:d235ec2ba7b8
- Parent:
- 2:684c698024c4
diff -r 684c698024c4 -r d235ec2ba7b8 main.cpp
--- a/main.cpp Thu Nov 15 12:35:00 2018 +0000
+++ b/main.cpp Mon Nov 19 11:22:10 2018 +0000
@@ -1,100 +1,120 @@
#include "mbed.h"
#include "C12832_lcd.h"
-
C12832_LCD lcd;
Timeout increment;
-BusIn up(p15);
-BusIn down(p12);
-BusIn left(p13);
-BusIn right(p16);
-BusIn centre(p14);
-
-int hours=0;
-int minutes=0;
-bool toggle=false;
-
-// How to detect if up is hold not press?
-
-if (up){ // switching between increasing hrs and minutes
- if (left) {
- inc_hrs();
- }
- else if (right){
- inc_min();
- }
- }
+InterruptIn down(p12);
+InterruptIn left (p13);
+InterruptIn centre(p14);
+InterruptIn up(p15);
+InterruptIn right(p16);
-if (down) //switching between decreasing minutes and hours
+int hours = 0;
+int minutes = 0;
+
+// switching between increasing hrs and minutes
+/**
+ Adjust minutes
+*/
+
+void adj_min()
+{
+ if (minutes > 59) {
+ minutes = 0;
+ }
+}
+
+void adj_hrs()
+{
+ if (hours > 23) {
+ hours = 0;
+ }
+}
+
+/**
+ Increment minutes
+*/
+void inc_min()
+{
+ minutes++;
+ adj_min();
+}
+void inc_hrs()
+{
+ hours++;
+ adj_hrs();
+}
+
+
+//function for decrementing
+
+void dec_min()
+{
+ minutes--;
+ adj_min();
+}
+void dec_hrs()
+{
+ hours--;
+ adj_hrs();
+}
+void Down()
+{
+ if (left) {
+ dec_hrs();
+ } else if (right) {
+ dec_min();
+ }
+}
+void Up()
{
if (left) {
inc_hrs();
} else if (right) {
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();
-
-}
-//function for decrementing
-/**
- Main entry point
-*/
-int main()
-{
- while(true) {
- increment.attach(&inc_min, 60.0);
}
- lcd.cls();
- lcd.locate(0,15);
+
+ /**
+ Main entry point
+ */
+ int main() {
-// 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
+ while (1) {
+ Down.rise(&Down_rise);
+ Up.rise(&Up_rise);
+ right.rise(&right_rise);
+ left.rise(&left_rise);
+ while (true) {
+ increment.attach(&inc_min, 60.0);
+
+
+ if (up) {
+ Up();
+ }
- if(minutes < 10) {
- mins = "0" + minutes;
- } else {
- mins = minutes;
- }
- lcd.printf("%s", mins);
+ if (down) { //switching between decreasing minutes and hours
+ Down();
+ }
+
+ lcd.cls();
+ lcd.locate(10, 10);
+
+ // Check if minutes are less than 10 so a 0 can be prefixed onto the display
+ char mins[10] = "00"; // String to display in lcd screen
-}
-}
+ if (minutes < 10) {
+ strcpy(mins, "0" + minutes);
+ } else {
+ strcpy(mins, "" + minutes);
+ }
+ lcd.printf("%s", mins);
+ lcd.locate(20, 10);
+ {
+ lcd.printf("%d", hours);
+ }
+ }
+ }
+ }
\ No newline at end of file