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.
Fork of Timer by
main.cpp@0:71df4c1d3c09, 2015-07-28 (annotated)
- Committer:
 - Jamestom999
 - Date:
 - Tue Jul 28 08:15:02 2015 +0000
 - Revision:
 - 0:71df4c1d3c09
 - Child:
 - 1:f5ee66d417f8
 
.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| Jamestom999 | 0:71df4c1d3c09 | 1 | #include "mbed.h" | 
| Jamestom999 | 0:71df4c1d3c09 | 2 | #include "Display.h" | 
| Jamestom999 | 0:71df4c1d3c09 | 3 | |
| Jamestom999 | 0:71df4c1d3c09 | 4 | #define Sound 0xA0 | 
| Jamestom999 | 0:71df4c1d3c09 | 5 | |
| Jamestom999 | 0:71df4c1d3c09 | 6 | Ticker t; | 
| Jamestom999 | 0:71df4c1d3c09 | 7 | DigitalIn Button_Launch(D1); | 
| Jamestom999 | 0:71df4c1d3c09 | 8 | DigitalIn Button_Reset (D0); | 
| Jamestom999 | 0:71df4c1d3c09 | 9 | DigitalIn Button_Sel1 (D6); | 
| Jamestom999 | 0:71df4c1d3c09 | 10 | DigitalIn Button_Sel2 (D7); | 
| Jamestom999 | 0:71df4c1d3c09 | 11 | DigitalOut LED_Timer (D3); | 
| Jamestom999 | 0:71df4c1d3c09 | 12 | DigitalOut LED_Finish (D4); | 
| Jamestom999 | 0:71df4c1d3c09 | 13 | DigitalOut LED_Launch (D5); | 
| Jamestom999 | 0:71df4c1d3c09 | 14 | PwmOut ServoOut (D10); | 
| Jamestom999 | 0:71df4c1d3c09 | 15 | DigitalIn Camera (D9); | 
| Jamestom999 | 0:71df4c1d3c09 | 16 | |
| Jamestom999 | 0:71df4c1d3c09 | 17 | I2C i2c(PTE25, PTE24); // sda, scl | 
| Jamestom999 | 0:71df4c1d3c09 | 18 | |
| Jamestom999 | 0:71df4c1d3c09 | 19 | |
| Jamestom999 | 0:71df4c1d3c09 | 20 | |
| Jamestom999 | 0:71df4c1d3c09 | 21 | int Time; //time in 10mS | 
| Jamestom999 | 0:71df4c1d3c09 | 22 | int timer; //Stores timer mode | 
| Jamestom999 | 0:71df4c1d3c09 | 23 | |
| Jamestom999 | 0:71df4c1d3c09 | 24 | void Servo(int deg){ | 
| Jamestom999 | 0:71df4c1d3c09 | 25 | ServoOut = 0.13f-(float(deg)/1900); | 
| Jamestom999 | 0:71df4c1d3c09 | 26 | } | 
| Jamestom999 | 0:71df4c1d3c09 | 27 | |
| Jamestom999 | 0:71df4c1d3c09 | 28 | int main() | 
| Jamestom999 | 0:71df4c1d3c09 | 29 | { | 
| Jamestom999 | 0:71df4c1d3c09 | 30 | int count=0; | 
| Jamestom999 | 0:71df4c1d3c09 | 31 | |
| Jamestom999 | 0:71df4c1d3c09 | 32 | wait(0.5); //Allow other IC's to power up | 
| Jamestom999 | 0:71df4c1d3c09 | 33 | DisplayInit(); | 
| Jamestom999 | 0:71df4c1d3c09 | 34 | |
| Jamestom999 | 0:71df4c1d3c09 | 35 | //--------------------------Timer----------------------------- | 
| Jamestom999 | 0:71df4c1d3c09 | 36 | Time=0; //reset time. | 
| Jamestom999 | 0:71df4c1d3c09 | 37 | timer=Reset; //Reset timer | 
| Jamestom999 | 0:71df4c1d3c09 | 38 | t.attach(&DisplayUpdate, 0.01); //Set the timer function as a ticker. | 
| Jamestom999 | 0:71df4c1d3c09 | 39 | |
| Jamestom999 | 0:71df4c1d3c09 | 40 | //DisplayScroll("dont crash get a badge"); | 
| Jamestom999 | 0:71df4c1d3c09 | 41 | //timer=Reset; | 
| Jamestom999 | 0:71df4c1d3c09 | 42 | |
| Jamestom999 | 0:71df4c1d3c09 | 43 | |
| Jamestom999 | 0:71df4c1d3c09 | 44 | char n='F'; | 
| Jamestom999 | 0:71df4c1d3c09 | 45 | i2c.write(Sound, &n, 1); | 
| Jamestom999 | 0:71df4c1d3c09 | 46 | |
| Jamestom999 | 0:71df4c1d3c09 | 47 | while(true){ | 
| Jamestom999 | 0:71df4c1d3c09 | 48 | count++; | 
| Jamestom999 | 0:71df4c1d3c09 | 49 | if(count>150000){ | 
| Jamestom999 | 0:71df4c1d3c09 | 50 | count=0; | 
| Jamestom999 | 0:71df4c1d3c09 | 51 | if(timer==Reset){ | 
| Jamestom999 | 0:71df4c1d3c09 | 52 | LED_Launch=!LED_Launch; | 
| Jamestom999 | 0:71df4c1d3c09 | 53 | } | 
| Jamestom999 | 0:71df4c1d3c09 | 54 | } | 
| Jamestom999 | 0:71df4c1d3c09 | 55 | |
| Jamestom999 | 0:71df4c1d3c09 | 56 | if(timer==Start){ | 
| Jamestom999 | 0:71df4c1d3c09 | 57 | LED_Timer=1; | 
| Jamestom999 | 0:71df4c1d3c09 | 58 | }else{ | 
| Jamestom999 | 0:71df4c1d3c09 | 59 | LED_Timer=0; | 
| Jamestom999 | 0:71df4c1d3c09 | 60 | } | 
| Jamestom999 | 0:71df4c1d3c09 | 61 | |
| Jamestom999 | 0:71df4c1d3c09 | 62 | if(timer==Pause){ | 
| Jamestom999 | 0:71df4c1d3c09 | 63 | LED_Finish=1; | 
| Jamestom999 | 0:71df4c1d3c09 | 64 | }else{ | 
| Jamestom999 | 0:71df4c1d3c09 | 65 | LED_Finish=0; | 
| Jamestom999 | 0:71df4c1d3c09 | 66 | } | 
| Jamestom999 | 0:71df4c1d3c09 | 67 | |
| Jamestom999 | 0:71df4c1d3c09 | 68 | if(!Button_Launch){ | 
| Jamestom999 | 0:71df4c1d3c09 | 69 | char n='s'; | 
| Jamestom999 | 0:71df4c1d3c09 | 70 | timer=Start; | 
| Jamestom999 | 0:71df4c1d3c09 | 71 | LED_Launch=1; | 
| Jamestom999 | 0:71df4c1d3c09 | 72 | i2c.write(Sound, &n, 1); | 
| Jamestom999 | 0:71df4c1d3c09 | 73 | }else if(timer!=Reset){ | 
| Jamestom999 | 0:71df4c1d3c09 | 74 | LED_Launch=0; | 
| Jamestom999 | 0:71df4c1d3c09 | 75 | } | 
| Jamestom999 | 0:71df4c1d3c09 | 76 | |
| Jamestom999 | 0:71df4c1d3c09 | 77 | if(Button_Reset&&(timer==Start)){ | 
| Jamestom999 | 0:71df4c1d3c09 | 78 | timer=Pause; | 
| Jamestom999 | 0:71df4c1d3c09 | 79 | wait(0.1f); | 
| Jamestom999 | 0:71df4c1d3c09 | 80 | while(Button_Reset){} | 
| Jamestom999 | 0:71df4c1d3c09 | 81 | wait(0.1f); | 
| Jamestom999 | 0:71df4c1d3c09 | 82 | } | 
| Jamestom999 | 0:71df4c1d3c09 | 83 | |
| Jamestom999 | 0:71df4c1d3c09 | 84 | if(Button_Reset&&(timer==Pause)){ | 
| Jamestom999 | 0:71df4c1d3c09 | 85 | timer=Reset; | 
| Jamestom999 | 0:71df4c1d3c09 | 86 | } | 
| Jamestom999 | 0:71df4c1d3c09 | 87 | |
| Jamestom999 | 0:71df4c1d3c09 | 88 | if(Camera){ | 
| Jamestom999 | 0:71df4c1d3c09 | 89 | timer=Pause; | 
| Jamestom999 | 0:71df4c1d3c09 | 90 | } | 
| Jamestom999 | 0:71df4c1d3c09 | 91 | |
| Jamestom999 | 0:71df4c1d3c09 | 92 | } | 
| Jamestom999 | 0:71df4c1d3c09 | 93 | |
| Jamestom999 | 0:71df4c1d3c09 | 94 | } | 
