Sequence LEDs

Dependencies:   TextLCD mbed

Fork of Y_01 by Yoshiyuki Takahashi

Committer:
seethe
Date:
Wed Feb 18 07:53:17 2015 +0000
Revision:
3:a9682a192956
Parent:
2:ce41adf02350
PWM

Who changed what in which revision?

UserRevisionLine numberNew 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(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7
seethe 1:80eb2d3e5974 9 AnalogIn in1(p15);
seethe 1:80eb2d3e5974 10 AnalogIn in2(p16);
seethe 1:80eb2d3e5974 11 AnalogIn in3(p17);
seethe 3:a9682a192956 12 //AnalogOut out(p18);
seethe 0:fbbd6271c1ac 13
seethe 3:a9682a192956 14 PwmOut led(LED1);
seethe 3:a9682a192956 15 PwmOut pwm(p21);
seethe 3:a9682a192956 16
seethe 3:a9682a192956 17 //DigitalOut DO[4]={LED1, LED2, LED3, LED4};
seethe 1:80eb2d3e5974 18 //int nCnt;
seethe 3:a9682a192956 19 /*
seethe 1:80eb2d3e5974 20 void led_blink(int cnt)
seethe 0:fbbd6271c1ac 21 {
seethe 0:fbbd6271c1ac 22 for(int n=0; n<4; n++){
seethe 1:80eb2d3e5974 23 if(n == cnt) DO[n] = 1;
seethe 0:fbbd6271c1ac 24 else DO[n] = 0;
seethe 0:fbbd6271c1ac 25 }
seethe 0:fbbd6271c1ac 26 }
seethe 3:a9682a192956 27 */
seethe 0:fbbd6271c1ac 28
seethe 0:fbbd6271c1ac 29 int main() {
seethe 1:80eb2d3e5974 30 int nCnt;
seethe 2:ce41adf02350 31 double rad;
seethe 2:ce41adf02350 32 double od;
seethe 1:80eb2d3e5974 33
seethe 3:a9682a192956 34 pwm.period(0.001);
seethe 1:80eb2d3e5974 35 nCnt = 0;
seethe 2:ce41adf02350 36 rad = 0.0;
seethe 3:a9682a192956 37 while(1) {
seethe 3:a9682a192956 38 for(float p = 0.0f; p < 1.0f; p += 0.1f) {
seethe 3:a9682a192956 39 led = pwm = p;
seethe 3:a9682a192956 40 wait(0.1);
seethe 3:a9682a192956 41 }
seethe 3:a9682a192956 42 }
seethe 3:a9682a192956 43
seethe 3:a9682a192956 44 /*
seethe 0:fbbd6271c1ac 45 while(1){
seethe 1:80eb2d3e5974 46 led_blink(nCnt);
seethe 1:80eb2d3e5974 47 nCnt++;
seethe 1:80eb2d3e5974 48 if(nCnt > 3)
seethe 1:80eb2d3e5974 49 nCnt = 0;
seethe 1:80eb2d3e5974 50
seethe 2:ce41adf02350 51 wait(0.01);
seethe 2:ce41adf02350 52
seethe 2:ce41adf02350 53 od = sin(rad);
seethe 2:ce41adf02350 54 rad += 0.01;
seethe 2:ce41adf02350 55 if(rad>(2*PI))
seethe 2:ce41adf02350 56 rad = 0.0;
seethe 2:ce41adf02350 57 out.write((float)(0.5*od+0.5));
seethe 2:ce41adf02350 58 lcd.printf("%.3f\n", od);
seethe 1:80eb2d3e5974 59 lcd.printf("%.2f,.%.2f,%.2f\n", in1.read(), in2.read(), in3.read());
seethe 0:fbbd6271c1ac 60 }
seethe 3:a9682a192956 61 */
seethe 0:fbbd6271c1ac 62 }