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
Timers.h@7:af2244bedcac, 2015-04-20 (annotated)
- Committer:
- pwright01
- Date:
- Mon Apr 20 09:58:04 2015 +0000
- Revision:
- 7:af2244bedcac
- Parent:
- 5:9af1305f7779
Minor cleanup, bug fixing.; ; Resolved bugs:; - An extra move is played randomly after a recording (due to play button press); - The last move in a recording is missed;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ShalajLawania | 5:9af1305f7779 | 1 | /********************************************** |
| ShalajLawania | 5:9af1305f7779 | 2 | * Bluetooth Controller Timers handling library |
| ShalajLawania | 5:9af1305f7779 | 3 | * Author: Shalaj Lawania. |
| ShalajLawania | 5:9af1305f7779 | 4 | **********************************************/ |
| ShalajLawania | 5:9af1305f7779 | 5 | |
| ShalajLawania | 5:9af1305f7779 | 6 | #include "mbed.h" |
| ShalajLawania | 5:9af1305f7779 | 7 | |
| ShalajLawania | 5:9af1305f7779 | 8 | /****************************************************************************** |
| ShalajLawania | 5:9af1305f7779 | 9 | * Timer wait_time: Record time no key is pressed - Wait Time |
| ShalajLawania | 5:9af1305f7779 | 10 | * Timer press_time: Record time a key is kept pressed - Press Time |
| ShalajLawania | 5:9af1305f7779 | 11 | * Timer play_time: Dummy timer to mimic press_time when sequence is played back |
| ShalajLawania | 5:9af1305f7779 | 12 | ******************************************************************************/ |
| ShalajLawania | 5:9af1305f7779 | 13 | |
| pwright01 | 7:af2244bedcac | 14 | Timer wait_time, press_time, play_time; |
| ShalajLawania | 5:9af1305f7779 | 15 | |
| ShalajLawania | 5:9af1305f7779 | 16 | /************************************************************ |
| ShalajLawania | 5:9af1305f7779 | 17 | * wait_times array: Stores Timer wait_time values for each move |
| ShalajLawania | 5:9af1305f7779 | 18 | * press_times array: Stores Timer press_time values for each move |
| ShalajLawania | 5:9af1305f7779 | 19 | ************************************************************/ |
| ShalajLawania | 5:9af1305f7779 | 20 | |
| ShalajLawania | 5:9af1305f7779 | 21 | unsigned long long wait_times[400]; //change index to increase recorded wait time |
| ShalajLawania | 5:9af1305f7779 | 22 | unsigned long long press_times[400]; //change index to increase recorded press time |
| ShalajLawania | 5:9af1305f7779 | 23 | |
| ShalajLawania | 5:9af1305f7779 | 24 | Serial pc(USBTX, USBRX); |
| ShalajLawania | 5:9af1305f7779 | 25 | |
| ShalajLawania | 5:9af1305f7779 | 26 | unsigned int j = 0; |
| ShalajLawania | 5:9af1305f7779 | 27 | unsigned long long display_play_time = 0; |
| ShalajLawania | 5:9af1305f7779 | 28 | |
| ShalajLawania | 5:9af1305f7779 | 29 | /****************************************************************************** |
| ShalajLawania | 5:9af1305f7779 | 30 | * press_time_stop() stops and resets the press_time timer that is recording the |
| ShalajLawania | 5:9af1305f7779 | 31 | * the amount of time a key is pressed. The value is stored in the press_times array |
| ShalajLawania | 5:9af1305f7779 | 32 | ******************************************************************************/ |
| ShalajLawania | 5:9af1305f7779 | 33 | |
| ShalajLawania | 5:9af1305f7779 | 34 | void press_time_stop() |
| ShalajLawania | 5:9af1305f7779 | 35 | { |
| ShalajLawania | 5:9af1305f7779 | 36 | press_time.stop(); |
| ShalajLawania | 5:9af1305f7779 | 37 | if(press_time.read_ms() > 0) { |
| ShalajLawania | 5:9af1305f7779 | 38 | press_times[j] = press_time.read_ms(); |
| ShalajLawania | 5:9af1305f7779 | 39 | pc.printf("\n\r Press Time: %d \n", press_times[j]); |
| ShalajLawania | 5:9af1305f7779 | 40 | } |
| ShalajLawania | 5:9af1305f7779 | 41 | press_time.reset(); |
| ShalajLawania | 5:9af1305f7779 | 42 | j++; |
| ShalajLawania | 5:9af1305f7779 | 43 | } |
| ShalajLawania | 5:9af1305f7779 | 44 | |
| ShalajLawania | 5:9af1305f7779 | 45 | /************************************************************************ |
| ShalajLawania | 5:9af1305f7779 | 46 | * play_time_stop() stops and resets the play_time timer that is recording |
| ShalajLawania | 5:9af1305f7779 | 47 | * time taken to play back a move. Ideally play_time should be equal |
| ShalajLawania | 5:9af1305f7779 | 48 | * to the press_time |
| ShalajLawania | 5:9af1305f7779 | 49 | ************************************************************************/ |
| ShalajLawania | 5:9af1305f7779 | 50 | |
| ShalajLawania | 5:9af1305f7779 | 51 | void play_time_stop() |
| ShalajLawania | 5:9af1305f7779 | 52 | { |
| ShalajLawania | 5:9af1305f7779 | 53 | play_time.stop(); |
| ShalajLawania | 5:9af1305f7779 | 54 | display_play_time = play_time.read_ms(); |
| ShalajLawania | 5:9af1305f7779 | 55 | if (display_play_time != 0) { |
| pwright01 | 7:af2244bedcac | 56 | pc.printf("\n\r Play Time: %d \n", display_play_time); |
| ShalajLawania | 5:9af1305f7779 | 57 | } |
| ShalajLawania | 5:9af1305f7779 | 58 | play_time.reset(); |
| ShalajLawania | 5:9af1305f7779 | 59 | } |