Andrew Harpin
/
LED_PWM
main.cpp@0:5b52db367115, 2009-11-26 (annotated)
- Committer:
- annodomini2
- Date:
- Thu Nov 26 15:52:53 2009 +0000
- Revision:
- 0:5b52db367115
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
annodomini2 | 0:5b52db367115 | 1 | #include "mbed.h" |
annodomini2 | 0:5b52db367115 | 2 | |
annodomini2 | 0:5b52db367115 | 3 | PwmOut myled(LED1); |
annodomini2 | 0:5b52db367115 | 4 | |
annodomini2 | 0:5b52db367115 | 5 | bool back = false; |
annodomini2 | 0:5b52db367115 | 6 | float drive = 0; |
annodomini2 | 0:5b52db367115 | 7 | |
annodomini2 | 0:5b52db367115 | 8 | Timer timer; |
annodomini2 | 0:5b52db367115 | 9 | |
annodomini2 | 0:5b52db367115 | 10 | int main() |
annodomini2 | 0:5b52db367115 | 11 | { |
annodomini2 | 0:5b52db367115 | 12 | int start = 0; |
annodomini2 | 0:5b52db367115 | 13 | int current = 0; |
annodomini2 | 0:5b52db367115 | 14 | |
annodomini2 | 0:5b52db367115 | 15 | timer.start(); |
annodomini2 | 0:5b52db367115 | 16 | |
annodomini2 | 0:5b52db367115 | 17 | myled = 1.0; |
annodomini2 | 0:5b52db367115 | 18 | |
annodomini2 | 0:5b52db367115 | 19 | while(1) |
annodomini2 | 0:5b52db367115 | 20 | { |
annodomini2 | 0:5b52db367115 | 21 | current = timer.read_ms(); |
annodomini2 | 0:5b52db367115 | 22 | |
annodomini2 | 0:5b52db367115 | 23 | if((current - start) >= 10) |
annodomini2 | 0:5b52db367115 | 24 | { |
annodomini2 | 0:5b52db367115 | 25 | if(back) |
annodomini2 | 0:5b52db367115 | 26 | { |
annodomini2 | 0:5b52db367115 | 27 | drive -= 0.01; |
annodomini2 | 0:5b52db367115 | 28 | |
annodomini2 | 0:5b52db367115 | 29 | if(drive <= 0) |
annodomini2 | 0:5b52db367115 | 30 | { |
annodomini2 | 0:5b52db367115 | 31 | drive = 0; |
annodomini2 | 0:5b52db367115 | 32 | back = false; |
annodomini2 | 0:5b52db367115 | 33 | } |
annodomini2 | 0:5b52db367115 | 34 | } |
annodomini2 | 0:5b52db367115 | 35 | else |
annodomini2 | 0:5b52db367115 | 36 | { |
annodomini2 | 0:5b52db367115 | 37 | drive += 0.01; |
annodomini2 | 0:5b52db367115 | 38 | |
annodomini2 | 0:5b52db367115 | 39 | if(drive >= 1) |
annodomini2 | 0:5b52db367115 | 40 | { |
annodomini2 | 0:5b52db367115 | 41 | drive = 0.999; |
annodomini2 | 0:5b52db367115 | 42 | back = true; |
annodomini2 | 0:5b52db367115 | 43 | } |
annodomini2 | 0:5b52db367115 | 44 | } |
annodomini2 | 0:5b52db367115 | 45 | |
annodomini2 | 0:5b52db367115 | 46 | myled = drive; |
annodomini2 | 0:5b52db367115 | 47 | start = timer.read_ms(); |
annodomini2 | 0:5b52db367115 | 48 | } |
annodomini2 | 0:5b52db367115 | 49 | } |
annodomini2 | 0:5b52db367115 | 50 | } |