Yoshiyuki Takahashi
/
Y_01
Sequence LEDs
My pocket
main.cpp@2:ce41adf02350, 2015-02-18 (annotated)
- Committer:
- seethe
- Date:
- Wed Feb 18 06:44:13 2015 +0000
- Revision:
- 2:ce41adf02350
- Parent:
- 1:80eb2d3e5974
SinWave
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
seethe | 0:fbbd6271c1ac | 1 | // Hello World! for the TextLCD |
seethe | 0:fbbd6271c1ac | 2 | |
seethe | 0:fbbd6271c1ac | 3 | #include "mbed.h" |
seethe | 0:fbbd6271c1ac | 4 | #include "TextLCD.h" |
seethe | 0:fbbd6271c1ac | 5 | |
seethe | 2:ce41adf02350 | 6 | #define PI 3.1415 |
seethe | 2:ce41adf02350 | 7 | |
seethe | 0:fbbd6271c1ac | 8 | //TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7 |
seethe | 0:fbbd6271c1ac | 9 | TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7 |
seethe | 1:80eb2d3e5974 | 10 | AnalogIn in1(p15); |
seethe | 1:80eb2d3e5974 | 11 | AnalogIn in2(p16); |
seethe | 1:80eb2d3e5974 | 12 | AnalogIn in3(p17); |
seethe | 1:80eb2d3e5974 | 13 | AnalogOut out(p18); |
seethe | 0:fbbd6271c1ac | 14 | |
seethe | 0:fbbd6271c1ac | 15 | DigitalOut DO[4]={LED1, LED2, LED3, LED4}; |
seethe | 1:80eb2d3e5974 | 16 | //int nCnt; |
seethe | 0:fbbd6271c1ac | 17 | |
seethe | 1:80eb2d3e5974 | 18 | void led_blink(int cnt) |
seethe | 0:fbbd6271c1ac | 19 | { |
seethe | 0:fbbd6271c1ac | 20 | for(int n=0; n<4; n++){ |
seethe | 1:80eb2d3e5974 | 21 | if(n == cnt) DO[n] = 1; |
seethe | 0:fbbd6271c1ac | 22 | else DO[n] = 0; |
seethe | 0:fbbd6271c1ac | 23 | } |
seethe | 0:fbbd6271c1ac | 24 | } |
seethe | 0:fbbd6271c1ac | 25 | |
seethe | 0:fbbd6271c1ac | 26 | int main() { |
seethe | 1:80eb2d3e5974 | 27 | int nCnt; |
seethe | 2:ce41adf02350 | 28 | double rad; |
seethe | 2:ce41adf02350 | 29 | double od; |
seethe | 1:80eb2d3e5974 | 30 | |
seethe | 1:80eb2d3e5974 | 31 | nCnt = 0; |
seethe | 2:ce41adf02350 | 32 | rad = 0.0; |
seethe | 0:fbbd6271c1ac | 33 | while(1){ |
seethe | 1:80eb2d3e5974 | 34 | led_blink(nCnt); |
seethe | 1:80eb2d3e5974 | 35 | nCnt++; |
seethe | 1:80eb2d3e5974 | 36 | if(nCnt > 3) |
seethe | 1:80eb2d3e5974 | 37 | nCnt = 0; |
seethe | 1:80eb2d3e5974 | 38 | |
seethe | 2:ce41adf02350 | 39 | wait(0.01); |
seethe | 2:ce41adf02350 | 40 | |
seethe | 2:ce41adf02350 | 41 | od = sin(rad); |
seethe | 2:ce41adf02350 | 42 | rad += 0.01; |
seethe | 2:ce41adf02350 | 43 | if(rad>(2*PI)) |
seethe | 2:ce41adf02350 | 44 | rad = 0.0; |
seethe | 2:ce41adf02350 | 45 | out.write((float)(0.5*od+0.5)); |
seethe | 2:ce41adf02350 | 46 | lcd.printf("%.3f\n", od); |
seethe | 1:80eb2d3e5974 | 47 | lcd.printf("%.2f,.%.2f,%.2f\n", in1.read(), in2.read(), in3.read()); |
seethe | 0:fbbd6271c1ac | 48 | } |
seethe | 0:fbbd6271c1ac | 49 | } |