homayoun mh
/
Arduino_Fade
Arduino_Fade sample code ported.
main.cpp@0:a594269e86ab, 2014-09-03 (annotated)
- Committer:
- homayoun
- Date:
- Wed Sep 03 12:33:33 2014 +0000
- Revision:
- 0:a594269e86ab
Arduino_Fade
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
homayoun | 0:a594269e86ab | 1 | #include "mbed.h" |
homayoun | 0:a594269e86ab | 2 | |
homayoun | 0:a594269e86ab | 3 | PwmOut led(LED1); |
homayoun | 0:a594269e86ab | 4 | |
homayoun | 0:a594269e86ab | 5 | float brightness = 0.0f; // how bright the LED is |
homayoun | 0:a594269e86ab | 6 | float fadeAmount = 0.02f; // how many points to fade the LED by |
homayoun | 0:a594269e86ab | 7 | |
homayoun | 0:a594269e86ab | 8 | // the setup routine runs once when you press reset: |
homayoun | 0:a594269e86ab | 9 | void setup() |
homayoun | 0:a594269e86ab | 10 | { |
homayoun | 0:a594269e86ab | 11 | |
homayoun | 0:a594269e86ab | 12 | } |
homayoun | 0:a594269e86ab | 13 | |
homayoun | 0:a594269e86ab | 14 | void loop() |
homayoun | 0:a594269e86ab | 15 | { |
homayoun | 0:a594269e86ab | 16 | brightness += fadeAmount; |
homayoun | 0:a594269e86ab | 17 | if (brightness <= 0.0f || brightness >= 1.0f) fadeAmount = -fadeAmount; // == doesn't work!!! |
homayoun | 0:a594269e86ab | 18 | led = brightness; |
homayoun | 0:a594269e86ab | 19 | wait(0.03); |
homayoun | 0:a594269e86ab | 20 | } |
homayoun | 0:a594269e86ab | 21 | |
homayoun | 0:a594269e86ab | 22 | int main() |
homayoun | 0:a594269e86ab | 23 | { |
homayoun | 0:a594269e86ab | 24 | setup(); |
homayoun | 0:a594269e86ab | 25 | while(1) loop(); |
homayoun | 0:a594269e86ab | 26 | } |