Adam Kraczkowski
/
PWMBlinking_LED_example
PWM Blinking LED example
main.cpp@0:ef666343e506, 2012-06-10 (annotated)
- Committer:
- zuko
- Date:
- Sun Jun 10 18:50:24 2012 +0000
- Revision:
- 0:ef666343e506
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zuko | 0:ef666343e506 | 1 | #include "mbed.h" |
zuko | 0:ef666343e506 | 2 | |
zuko | 0:ef666343e506 | 3 | PwmOut led1(LED1); |
zuko | 0:ef666343e506 | 4 | PwmOut led2(LED2); |
zuko | 0:ef666343e506 | 5 | PwmOut led3(LED3); |
zuko | 0:ef666343e506 | 6 | PwmOut led4(LED4); |
zuko | 0:ef666343e506 | 7 | |
zuko | 0:ef666343e506 | 8 | |
zuko | 0:ef666343e506 | 9 | int main() { |
zuko | 0:ef666343e506 | 10 | int a = -1; |
zuko | 0:ef666343e506 | 11 | float max = 1; |
zuko | 0:ef666343e506 | 12 | float medium = 0.2; |
zuko | 0:ef666343e506 | 13 | float low = 0.01; |
zuko | 0:ef666343e506 | 14 | |
zuko | 0:ef666343e506 | 15 | while(1) { |
zuko | 0:ef666343e506 | 16 | a += 1; |
zuko | 0:ef666343e506 | 17 | if (a == 12) { |
zuko | 0:ef666343e506 | 18 | a = 0; |
zuko | 0:ef666343e506 | 19 | } |
zuko | 0:ef666343e506 | 20 | |
zuko | 0:ef666343e506 | 21 | wait(0.5); |
zuko | 0:ef666343e506 | 22 | switch(a){ |
zuko | 0:ef666343e506 | 23 | case 0: |
zuko | 0:ef666343e506 | 24 | led1 = max; |
zuko | 0:ef666343e506 | 25 | led2 = 0; |
zuko | 0:ef666343e506 | 26 | led3 = 0; |
zuko | 0:ef666343e506 | 27 | led4 = 0; |
zuko | 0:ef666343e506 | 28 | break; |
zuko | 0:ef666343e506 | 29 | case 1: |
zuko | 0:ef666343e506 | 30 | led1 = medium; |
zuko | 0:ef666343e506 | 31 | led2 = max; |
zuko | 0:ef666343e506 | 32 | led3 = 0; |
zuko | 0:ef666343e506 | 33 | led4 = 0; |
zuko | 0:ef666343e506 | 34 | break; |
zuko | 0:ef666343e506 | 35 | case 2: |
zuko | 0:ef666343e506 | 36 | led1 = low; |
zuko | 0:ef666343e506 | 37 | led2 = medium; |
zuko | 0:ef666343e506 | 38 | led3 = max; |
zuko | 0:ef666343e506 | 39 | led4 = 0; |
zuko | 0:ef666343e506 | 40 | break; |
zuko | 0:ef666343e506 | 41 | case 3: |
zuko | 0:ef666343e506 | 42 | led1 = 0; |
zuko | 0:ef666343e506 | 43 | led2 = low; |
zuko | 0:ef666343e506 | 44 | led3 = medium; |
zuko | 0:ef666343e506 | 45 | led4 = max; |
zuko | 0:ef666343e506 | 46 | break; |
zuko | 0:ef666343e506 | 47 | case 4: |
zuko | 0:ef666343e506 | 48 | led1 = 0; |
zuko | 0:ef666343e506 | 49 | led2 = 0; |
zuko | 0:ef666343e506 | 50 | led3 = low; |
zuko | 0:ef666343e506 | 51 | led4 = max; |
zuko | 0:ef666343e506 | 52 | break; |
zuko | 0:ef666343e506 | 53 | case 5: |
zuko | 0:ef666343e506 | 54 | led1 = 0; |
zuko | 0:ef666343e506 | 55 | led2 = 0; |
zuko | 0:ef666343e506 | 56 | led3 = 0; |
zuko | 0:ef666343e506 | 57 | led4 = max; |
zuko | 0:ef666343e506 | 58 | break; |
zuko | 0:ef666343e506 | 59 | case 6: |
zuko | 0:ef666343e506 | 60 | led1 = 0; |
zuko | 0:ef666343e506 | 61 | led2 = 0; |
zuko | 0:ef666343e506 | 62 | led3 = 0; |
zuko | 0:ef666343e506 | 63 | led4 = max; |
zuko | 0:ef666343e506 | 64 | break; |
zuko | 0:ef666343e506 | 65 | case 7: |
zuko | 0:ef666343e506 | 66 | led1 = 0; |
zuko | 0:ef666343e506 | 67 | led2 = 0; |
zuko | 0:ef666343e506 | 68 | led3 = max; |
zuko | 0:ef666343e506 | 69 | led4 = medium; |
zuko | 0:ef666343e506 | 70 | break; |
zuko | 0:ef666343e506 | 71 | case 8: |
zuko | 0:ef666343e506 | 72 | led1 = 0; |
zuko | 0:ef666343e506 | 73 | led2 = max; |
zuko | 0:ef666343e506 | 74 | led3 = medium; |
zuko | 0:ef666343e506 | 75 | led4 = low; |
zuko | 0:ef666343e506 | 76 | break; |
zuko | 0:ef666343e506 | 77 | case 9: |
zuko | 0:ef666343e506 | 78 | led1 = max; |
zuko | 0:ef666343e506 | 79 | led2 = medium; |
zuko | 0:ef666343e506 | 80 | led3 = low; |
zuko | 0:ef666343e506 | 81 | led4 = 0; |
zuko | 0:ef666343e506 | 82 | break; |
zuko | 0:ef666343e506 | 83 | case 10: |
zuko | 0:ef666343e506 | 84 | led1 = max; |
zuko | 0:ef666343e506 | 85 | led2 = low; |
zuko | 0:ef666343e506 | 86 | led3 = 0; |
zuko | 0:ef666343e506 | 87 | led4 = 0; |
zuko | 0:ef666343e506 | 88 | break; |
zuko | 0:ef666343e506 | 89 | case 11: |
zuko | 0:ef666343e506 | 90 | led1 = max; |
zuko | 0:ef666343e506 | 91 | led2 = 0; |
zuko | 0:ef666343e506 | 92 | led3 = 0; |
zuko | 0:ef666343e506 | 93 | led4 = 0; |
zuko | 0:ef666343e506 | 94 | break; |
zuko | 0:ef666343e506 | 95 | } |
zuko | 0:ef666343e506 | 96 | } |
zuko | 0:ef666343e506 | 97 | } |