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.
main.cpp@1:5ceb4255be68, 2021-05-27 (annotated)
- Committer:
- marumbo
- Date:
- Thu May 27 15:20:42 2021 +0000
- Revision:
- 1:5ceb4255be68
- Parent:
- 0:dd0d7dbadcbd
- Child:
- 2:4eff114c7219
made changes to add blinking logic ,; algotirhm needs fixing for state;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marumbo | 0:dd0d7dbadcbd | 1 | #include "mbed.h" |
marumbo | 0:dd0d7dbadcbd | 2 | |
marumbo | 0:dd0d7dbadcbd | 3 | DigitalOut myled(LED1); |
marumbo | 0:dd0d7dbadcbd | 4 | |
marumbo | 1:5ceb4255be68 | 5 | DigitalIn mySwitch(p7); |
marumbo | 1:5ceb4255be68 | 6 | |
marumbo | 1:5ceb4255be68 | 7 | DigitalOut yellowLed(p5); |
marumbo | 1:5ceb4255be68 | 8 | |
marumbo | 1:5ceb4255be68 | 9 | DigitalOut redLed(p6); |
marumbo | 1:5ceb4255be68 | 10 | |
marumbo | 1:5ceb4255be68 | 11 | int switchState = 0; |
marumbo | 1:5ceb4255be68 | 12 | |
marumbo | 1:5ceb4255be68 | 13 | void BlinkYellowLed() |
marumbo | 1:5ceb4255be68 | 14 | { |
marumbo | 1:5ceb4255be68 | 15 | yellowLed =1; |
marumbo | 1:5ceb4255be68 | 16 | wait(0.5); |
marumbo | 1:5ceb4255be68 | 17 | yellowLed = 0; |
marumbo | 1:5ceb4255be68 | 18 | wait(0.5); |
marumbo | 1:5ceb4255be68 | 19 | |
marumbo | 1:5ceb4255be68 | 20 | } |
marumbo | 1:5ceb4255be68 | 21 | |
marumbo | 1:5ceb4255be68 | 22 | |
marumbo | 0:dd0d7dbadcbd | 23 | int main() { |
marumbo | 1:5ceb4255be68 | 24 | printf("Start program \n"); |
marumbo | 1:5ceb4255be68 | 25 | printf("Initialize yellow Led to on \n") |
marumbo | 1:5ceb4255be68 | 26 | yellowLed = 1; |
marumbo | 1:5ceb4255be68 | 27 | redLed= 0; |
marumbo | 1:5ceb4255be68 | 28 | switchState = 0; |
marumbo | 1:5ceb4255be68 | 29 | |
marumbo | 1:5ceb4255be68 | 30 | while(1) { |
marumbo | 1:5ceb4255be68 | 31 | printf("Entered Loop \n"); |
marumbo | 1:5ceb4255be68 | 32 | |
marumbo | 1:5ceb4255be68 | 33 | |
marumbo | 1:5ceb4255be68 | 34 | printf("Value of my switch %d\n", mySwitch.read()); |
marumbo | 1:5ceb4255be68 | 35 | printf("Switch state %d\n", switchState); |
marumbo | 1:5ceb4255be68 | 36 | |
marumbo | 1:5ceb4255be68 | 37 | if(mySwitch == 1) |
marumbo | 1:5ceb4255be68 | 38 | { |
marumbo | 1:5ceb4255be68 | 39 | printf("Value of my switch %d\n", mySwitch.read()); |
marumbo | 1:5ceb4255be68 | 40 | |
marumbo | 1:5ceb4255be68 | 41 | yellowLed = 0; |
marumbo | 1:5ceb4255be68 | 42 | wait(0.5); |
marumbo | 1:5ceb4255be68 | 43 | |
marumbo | 1:5ceb4255be68 | 44 | if(switchState == 0) |
marumbo | 1:5ceb4255be68 | 45 | { |
marumbo | 1:5ceb4255be68 | 46 | |
marumbo | 1:5ceb4255be68 | 47 | for(int i =0; i<5; i++) |
marumbo | 1:5ceb4255be68 | 48 | { |
marumbo | 1:5ceb4255be68 | 49 | BlinkYellowLed(); |
marumbo | 1:5ceb4255be68 | 50 | |
marumbo | 1:5ceb4255be68 | 51 | } |
marumbo | 1:5ceb4255be68 | 52 | |
marumbo | 1:5ceb4255be68 | 53 | yellowLed = 0; |
marumbo | 1:5ceb4255be68 | 54 | switchState = 1; |
marumbo | 1:5ceb4255be68 | 55 | |
marumbo | 1:5ceb4255be68 | 56 | |
marumbo | 1:5ceb4255be68 | 57 | } |
marumbo | 1:5ceb4255be68 | 58 | |
marumbo | 1:5ceb4255be68 | 59 | else |
marumbo | 1:5ceb4255be68 | 60 | { |
marumbo | 1:5ceb4255be68 | 61 | yellowLed = 0; |
marumbo | 1:5ceb4255be68 | 62 | switchState = 1; |
marumbo | 1:5ceb4255be68 | 63 | } |
marumbo | 1:5ceb4255be68 | 64 | |
marumbo | 1:5ceb4255be68 | 65 | |
marumbo | 1:5ceb4255be68 | 66 | } |
marumbo | 1:5ceb4255be68 | 67 | else |
marumbo | 1:5ceb4255be68 | 68 | { |
marumbo | 1:5ceb4255be68 | 69 | yellowLed = 1; |
marumbo | 1:5ceb4255be68 | 70 | switchState = 1; |
marumbo | 1:5ceb4255be68 | 71 | } |
marumbo | 1:5ceb4255be68 | 72 | |
marumbo | 1:5ceb4255be68 | 73 | wait_ms(500); |
marumbo | 0:dd0d7dbadcbd | 74 | } |
marumbo | 0:dd0d7dbadcbd | 75 | } |