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: Hexi_KW40Z Hexi_OLED_SSD1351
Revision 0:623612f2cc48, committed 2017-04-19
- Comitter:
- fusop
- Date:
- Wed Apr 19 15:00:09 2017 +0000
- Commit message:
- Final version of Stopwatch;
Changed in this revision
diff -r 000000000000 -r 623612f2cc48 .gitignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Wed Apr 19 15:00:09 2017 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
diff -r 000000000000 -r 623612f2cc48 Functions.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Functions.h Wed Apr 19 15:00:09 2017 +0000
@@ -0,0 +1,66 @@
+
+
+extern void Button_Init (void);
+extern void StartHP (void);
+extern void StopHP (void const *n);
+extern DigitalOut hp(PTB9);
+extern KW40Z kw40z_device(PTE24, PTE25);
+extern RtosTimer hpTime(StopHP, osTimerOnce);
+extern int but;
+
+void StartHP (void);
+void StopHP (void const *n);
+
+int but = 1;
+
+//Buttons-------------------------------
+
+void ButtonUp(void)
+{
+ StartHP();
+}
+
+void ButtonDown(void)
+{
+ StartHP();
+ but = 0;
+}
+
+void ButtonRight(void)
+{
+ StartHP();
+ but = 1;
+}
+
+void ButtonLeft(void)
+{
+ StartHP();
+ but = 2;
+}
+
+void ButtonSlide(void)
+{
+ StartHP();
+}
+
+void Button_Init (void)
+{
+ kw40z_device.attach_buttonUp(&ButtonUp);
+ kw40z_device.attach_buttonDown(&ButtonDown);
+ kw40z_device.attach_buttonLeft(&ButtonLeft);
+ kw40z_device.attach_buttonRight(&ButtonRight);
+}
+
+//Haptic -----------------------------------------
+
+void StartHP(void)
+{
+ hpTime.start(50);
+ hp = 1;
+}
+
+void StopHP(void const *n)
+{
+ hp = 0;
+ hpTime.stop();
+}
\ No newline at end of file
diff -r 000000000000 -r 623612f2cc48 Hexi_KW40Z.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hexi_KW40Z.lib Wed Apr 19 15:00:09 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Hexiwear/code/Hexi_KW40Z/#3f5ed7abc5c7
diff -r 000000000000 -r 623612f2cc48 Hexi_OLED_SSD1351.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hexi_OLED_SSD1351.lib Wed Apr 19 15:00:09 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Hexiwear/code/Hexi_OLED_SSD1351/#ae5fad429790
diff -r 000000000000 -r 623612f2cc48 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Apr 19 15:00:09 2017 +0000
@@ -0,0 +1,82 @@
+//Filarius Peter Usop
+//Mini Project 1
+//Uses LEDs, Buttons, Haptic, and OLEd
+
+#include "mbed.h"
+#include "Hexi_OLED_SSD1351.h"
+#include "Hexi_KW40Z.h"
+#include "Functions.h"
+#include "string.h"
+
+//SSD1351 Driver (OLED) Instantiation
+SSD1351 oled(PTB22, PTB21, PTC13, PTB20, PTE6, PTD15);
+
+Timer t;
+
+int main (void)
+{
+ //Initialize buttons
+ Button_Init();
+
+ //Initialize the text properties to default
+ oled_text_properties_t textProp = {0};
+ oled.GetTextProperties(&textProp);
+
+ //String Pointer
+ char text[20];
+
+ //Flag
+ int flag = 1;
+
+ //Clear screen
+ oled.DrawBox(0,0,96,96,COLOR_BLACK);
+
+ //Top Title
+ strcpy((char *) text, "Stopwatch");
+ textProp.fontColor = COLOR_WHITE;
+ textProp.alignParam = OLED_TEXT_ALIGN_CENTER;
+ oled.SetTextProperties(&textProp);
+ oled.TextBox((const uint8_t *) text,0,0,96,15);
+
+ textProp.fontColor = COLOR_RED;
+ oled.SetTextProperties(&textProp);
+
+ t.start(); //Start stopwatch. You may remove this line
+
+ //Print to OLED
+ sprintf(text, "%.0f", t.read());
+ oled.TextBox((uint8_t *) text,0,40,96,15);
+
+ while (1) {
+ Thread::wait(1000); //Refresh every 1 second
+ if (flag == 1) //Down button: Stops and resets the stopwatch
+ {
+ t.stop();
+ t.reset();
+ sprintf(text, "%.0f", t.read());
+ flag++;
+ }
+ else if (flag == 2) //Right button: Starts the stopwatch
+ {
+ if (but == 1)
+ {
+ t.start();
+ flag++;
+ }
+ else if (but == 0) flag--;
+ }
+ else if (flag == 3) //Left button: Stops the stopwatch
+ {
+ if (but == 2)
+ {
+ t.stop();
+ flag--;
+ }
+ else if (but == 0) flag = flag-2;
+ }
+
+ //Update value on OLED
+ sprintf(text, "%.0f", t.read());
+ oled.TextBox((uint8_t *) text,0,40,96,15);
+ }
+}
diff -r 000000000000 -r 623612f2cc48 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Wed Apr 19 15:00:09 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#bcf7085d85b2811b5d68bdda192c754eadfb8f88