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@2:4322a370e8d1, 2015-07-30 (annotated)
- Committer:
- Jamestom999
- Date:
- Thu Jul 30 16:18:40 2015 +0000
- Revision:
- 2:4322a370e8d1
- Parent:
- 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 | 1:f5ee66d417f8 | 5 | #define Servo 0x88 |
Jamestom999 | 0:71df4c1d3c09 | 6 | |
Jamestom999 | 0:71df4c1d3c09 | 7 | Ticker t; |
Jamestom999 | 0:71df4c1d3c09 | 8 | DigitalIn Button_Launch(D1); |
Jamestom999 | 0:71df4c1d3c09 | 9 | DigitalIn Button_Reset (D0); |
Jamestom999 | 0:71df4c1d3c09 | 10 | DigitalIn Button_Sel1 (D6); |
Jamestom999 | 0:71df4c1d3c09 | 11 | DigitalIn Button_Sel2 (D7); |
Jamestom999 | 0:71df4c1d3c09 | 12 | DigitalOut LED_Timer (D3); |
Jamestom999 | 0:71df4c1d3c09 | 13 | DigitalOut LED_Finish (D4); |
Jamestom999 | 0:71df4c1d3c09 | 14 | DigitalOut LED_Launch (D5); |
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 | int main() |
Jamestom999 | 0:71df4c1d3c09 | 25 | { |
Jamestom999 | 0:71df4c1d3c09 | 26 | int count=0; |
Jamestom999 | 0:71df4c1d3c09 | 27 | |
Jamestom999 | 2:4322a370e8d1 | 28 | LED_Launch=1; |
Jamestom999 | 2:4322a370e8d1 | 29 | |
Jamestom999 | 0:71df4c1d3c09 | 30 | wait(0.5); //Allow other IC's to power up |
Jamestom999 | 0:71df4c1d3c09 | 31 | DisplayInit(); |
Jamestom999 | 0:71df4c1d3c09 | 32 | |
Jamestom999 | 0:71df4c1d3c09 | 33 | //--------------------------Timer----------------------------- |
Jamestom999 | 0:71df4c1d3c09 | 34 | Time=0; //reset time. |
Jamestom999 | 0:71df4c1d3c09 | 35 | timer=Reset; //Reset timer |
Jamestom999 | 0:71df4c1d3c09 | 36 | t.attach(&DisplayUpdate, 0.01); //Set the timer function as a ticker. |
Jamestom999 | 0:71df4c1d3c09 | 37 | |
Jamestom999 | 1:f5ee66d417f8 | 38 | /* |
Jamestom999 | 1:f5ee66d417f8 | 39 | while(1){ |
Jamestom999 | 1:f5ee66d417f8 | 40 | char cmd[4]={1,2,3,4}; |
Jamestom999 | 1:f5ee66d417f8 | 41 | i2c.write(Servo, cmd, 1); |
Jamestom999 | 1:f5ee66d417f8 | 42 | } |
Jamestom999 | 1:f5ee66d417f8 | 43 | */ |
Jamestom999 | 1:f5ee66d417f8 | 44 | |
Jamestom999 | 0:71df4c1d3c09 | 45 | //DisplayScroll("dont crash get a badge"); |
Jamestom999 | 0:71df4c1d3c09 | 46 | //timer=Reset; |
Jamestom999 | 0:71df4c1d3c09 | 47 | |
Jamestom999 | 2:4322a370e8d1 | 48 | |
Jamestom999 | 2:4322a370e8d1 | 49 | while(true){ |
Jamestom999 | 0:71df4c1d3c09 | 50 | |
Jamestom999 | 1:f5ee66d417f8 | 51 | if(!Button_Launch && timer==Start){ |
Jamestom999 | 1:f5ee66d417f8 | 52 | Time+=1000; |
Jamestom999 | 2:4322a370e8d1 | 53 | wait(0.2f); |
Jamestom999 | 1:f5ee66d417f8 | 54 | while(!Button_Launch){} |
Jamestom999 | 2:4322a370e8d1 | 55 | wait(0.2f); |
Jamestom999 | 1:f5ee66d417f8 | 56 | } |
Jamestom999 | 1:f5ee66d417f8 | 57 | |
Jamestom999 | 1:f5ee66d417f8 | 58 | if(!Button_Launch && timer==Reset){ |
Jamestom999 | 1:f5ee66d417f8 | 59 | char n='S'; |
Jamestom999 | 1:f5ee66d417f8 | 60 | LED_Launch=0; |
Jamestom999 | 1:f5ee66d417f8 | 61 | wait(1); |
Jamestom999 | 1:f5ee66d417f8 | 62 | |
Jamestom999 | 1:f5ee66d417f8 | 63 | if(!Button_Sel1){ |
Jamestom999 | 1:f5ee66d417f8 | 64 | i2c.write(Sound, &n, 1);//Start sound |
Jamestom999 | 1:f5ee66d417f8 | 65 | } |
Jamestom999 | 1:f5ee66d417f8 | 66 | |
Jamestom999 | 1:f5ee66d417f8 | 67 | wait(0.5); //Flashing to sync with sound |
Jamestom999 | 0:71df4c1d3c09 | 68 | LED_Launch=1; |
Jamestom999 | 1:f5ee66d417f8 | 69 | DisplayNumber(15,15,3,15,15); |
Jamestom999 | 1:f5ee66d417f8 | 70 | wait(0.5); |
Jamestom999 | 1:f5ee66d417f8 | 71 | LED_Launch=0; |
Jamestom999 | 1:f5ee66d417f8 | 72 | wait(0.5); |
Jamestom999 | 1:f5ee66d417f8 | 73 | LED_Launch=1; |
Jamestom999 | 1:f5ee66d417f8 | 74 | DisplayNumber(15,15,2,15,15); |
Jamestom999 | 1:f5ee66d417f8 | 75 | wait(0.5); |
Jamestom999 | 0:71df4c1d3c09 | 76 | LED_Launch=0; |
Jamestom999 | 1:f5ee66d417f8 | 77 | wait(0.5); |
Jamestom999 | 1:f5ee66d417f8 | 78 | LED_Launch=1; |
Jamestom999 | 1:f5ee66d417f8 | 79 | DisplayNumber(15,15,1,15,15); |
Jamestom999 | 1:f5ee66d417f8 | 80 | wait(0.5); |
Jamestom999 | 1:f5ee66d417f8 | 81 | LED_Launch=0; |
Jamestom999 | 1:f5ee66d417f8 | 82 | wait(0.5); |
Jamestom999 | 1:f5ee66d417f8 | 83 | LED_Launch=1; |
Jamestom999 | 1:f5ee66d417f8 | 84 | timer=Start; //Start the timer |
Jamestom999 | 1:f5ee66d417f8 | 85 | LED_Timer=1; |
Jamestom999 | 1:f5ee66d417f8 | 86 | wait(2); |
Jamestom999 | 1:f5ee66d417f8 | 87 | LED_Launch=0; //Turn off the light |
Jamestom999 | 2:4322a370e8d1 | 88 | wait(0.2f); |
Jamestom999 | 0:71df4c1d3c09 | 89 | } |
Jamestom999 | 0:71df4c1d3c09 | 90 | |
Jamestom999 | 2:4322a370e8d1 | 91 | if(Button_Reset && (timer==Start)){ |
Jamestom999 | 1:f5ee66d417f8 | 92 | char n='F'; |
Jamestom999 | 0:71df4c1d3c09 | 93 | timer=Pause; |
Jamestom999 | 1:f5ee66d417f8 | 94 | if(!Button_Sel1){ |
Jamestom999 | 1:f5ee66d417f8 | 95 | i2c.write(Sound, &n, 1); //End sound |
Jamestom999 | 1:f5ee66d417f8 | 96 | } |
Jamestom999 | 0:71df4c1d3c09 | 97 | wait(0.1f); |
Jamestom999 | 0:71df4c1d3c09 | 98 | while(Button_Reset){} |
Jamestom999 | 2:4322a370e8d1 | 99 | LED_Timer=0; |
Jamestom999 | 2:4322a370e8d1 | 100 | LED_Finish=1; |
Jamestom999 | 2:4322a370e8d1 | 101 | wait(0.2); |
Jamestom999 | 0:71df4c1d3c09 | 102 | } |
Jamestom999 | 0:71df4c1d3c09 | 103 | |
Jamestom999 | 2:4322a370e8d1 | 104 | if(Button_Reset && (timer==Pause)){ |
Jamestom999 | 0:71df4c1d3c09 | 105 | timer=Reset; |
Jamestom999 | 2:4322a370e8d1 | 106 | LED_Finish=0; |
Jamestom999 | 2:4322a370e8d1 | 107 | wait(0.2); |
Jamestom999 | 0:71df4c1d3c09 | 108 | } |
Jamestom999 | 0:71df4c1d3c09 | 109 | |
Jamestom999 | 1:f5ee66d417f8 | 110 | if(Camera && (timer==Start)){ |
Jamestom999 | 1:f5ee66d417f8 | 111 | char n='F'; |
Jamestom999 | 0:71df4c1d3c09 | 112 | timer=Pause; |
Jamestom999 | 1:f5ee66d417f8 | 113 | if(!Button_Sel1){ |
Jamestom999 | 1:f5ee66d417f8 | 114 | i2c.write(Sound, &n, 1); //End sound |
Jamestom999 | 1:f5ee66d417f8 | 115 | } |
Jamestom999 | 2:4322a370e8d1 | 116 | LED_Timer=0; |
Jamestom999 | 2:4322a370e8d1 | 117 | LED_Finish=1; |
Jamestom999 | 2:4322a370e8d1 | 118 | wait(0.2); |
Jamestom999 | 0:71df4c1d3c09 | 119 | } |
Jamestom999 | 0:71df4c1d3c09 | 120 | |
Jamestom999 | 0:71df4c1d3c09 | 121 | } |
Jamestom999 | 0:71df4c1d3c09 | 122 | |
Jamestom999 | 0:71df4c1d3c09 | 123 | } |