final project update
Dependencies: mbed
Fork of DISCO_SMT32L4_pwm_PB3 by
Diff: main.cpp
- Revision:
- 6:57bad75ec95b
- Parent:
- 5:620125c08317
- Child:
- 7:662af5825808
--- a/main.cpp Thu Apr 19 22:54:33 2018 +0000 +++ b/main.cpp Wed Apr 25 00:21:14 2018 +0000 @@ -1,8 +1,8 @@ #include "mbed.h" Serial pc(SERIAL_TX, SERIAL_RX); -PwmOut mypwm(PWM_OUT); -PwmOut ndpwm(LED1); -PwmOut rdpwm(JOYSTICK_LEFT); +PwmOut mypwm(PWM_OUT); // PB3 - blue +PwmOut red_pwm(LED1); // PE8-red +PwmOut green_pwm(JOYSTICK_LEFT);// PA1 GREEN #define UP 1 @@ -13,7 +13,7 @@ uint8_t count_dir = UP; while(loop==1) { - printf("Enter d to exit loop"); + printf("Enter d to exit loop\n\r"); char a = pc.getc(); for(int i=0; i<10; i++) { @@ -38,7 +38,7 @@ } if(a =='d') { - printf("Exiting loop"); + printf("Exiting loop\n\r"); loop=0; } } @@ -48,7 +48,7 @@ uint8_t count_dir = UP; while(loop==1) { - printf("Enter d to exit loop"); + printf("Enter d to exit loop\n\r"); char a = pc.getc(); for(int i=0; i<10; i++) { @@ -56,20 +56,20 @@ if(count_dir == UP) { - ndpwm = ndpwm + 0.1; - if(ndpwm == 1.00) + red_pwm = red_pwm + 0.1; + if(red_pwm == 1.00) { // if hit one, start counting down count_dir = DOWN; } } else if(count_dir == DOWN) { - ndpwm = ndpwm - 0.1; - if(ndpwm == 0.0) + red_pwm = red_pwm - 0.1; + if(red_pwm == 0.0) { // if hit zero, start counting up count_dir = UP; } } - printf("pwm set to %.2f %%\n\r", ndpwm.read() * 100); + printf("pwm set to %.2f %%\n\r", red_pwm.read() * 100); } if(a =='d') { @@ -83,7 +83,7 @@ uint8_t count_dir = UP; while(loop==1) { - printf("Enter d to exit loop"); + printf("Enter d to exit loop\n\r"); char a = pc.getc(); for(int i=0; i<10; i++) { @@ -91,24 +91,24 @@ if(count_dir == UP) { - rdpwm = rdpwm + 0.1; - if(rdpwm == 1.00) + green_pwm = green_pwm + 0.1; + if(green_pwm == 1.00) { // if hit one, start counting down count_dir = DOWN; } } else if(count_dir == DOWN) { - rdpwm = rdpwm - 0.1; - if(rdpwm == 0.0) + green_pwm = green_pwm - 0.1; + if(green_pwm == 0.0) { // if hit zero, start counting up count_dir = UP; } } - printf("pwm set to %.2f %%\n\r", rdpwm.read() * 100); + printf("pwm set to %.2f %%\n\r", green_pwm.read() * 100); } if(a =='d') { - printf("Exiting loop"); + printf("Exiting loop\n\r"); loop=0; } } @@ -118,14 +118,14 @@ uint8_t count_dir = UP; while(loop==1) { - printf("Enter d to exit loop"); + printf("Enter d to exit loop\n\r"); char a = pc.getc(); for(int i=0; i<10; i++) { if(count_dir == UP) { - ndpwm = ndpwm + 0.1; + red_pwm = red_pwm + 0.1; mypwm = mypwm + 0.1; if(mypwm == 1.00) { // if hit one, start counting down @@ -133,7 +133,7 @@ } } else if(count_dir == DOWN) { - ndpwm = ndpwm - 0.1; + red_pwm = red_pwm - 0.1; mypwm = mypwm - 0.1; if(mypwm == 0.0) { // if hit zero, start counting up @@ -141,7 +141,7 @@ } } printf("pwm set to %.2f %%\n\r", mypwm.read() * 100); - printf("2nd pwm set to %.2f %%\n", ndpwm.read() * 100); + printf("2nd pwm set to %.2f %%\n\r", red_pwm.read() * 100); } if(a =='d') { @@ -155,14 +155,14 @@ uint8_t count_dir = UP; while(loop==1) { - printf("Enter d to exit loop"); + printf("Enter d to exit loop\n\r"); char a = pc.getc(); for(int i=0; i<10; i++) { if(count_dir == UP) { - rdpwm = rdpwm + 0.1; + green_pwm = green_pwm + 0.1; mypwm = mypwm + 0.1; if(mypwm == 1.00) { // if hit one, start counting down @@ -170,7 +170,7 @@ } } else if(count_dir == DOWN) { - rdpwm = rdpwm - 0.1; + green_pwm = green_pwm - 0.1; mypwm = mypwm - 0.1; if(mypwm == 0.0) { // if hit zero, start counting up @@ -178,11 +178,11 @@ } } printf("pwm set to %.2f %%\n\r", mypwm.read() * 100); - printf("2nd pwm set to %.2f %%\n", rdpwm.read() * 100); + printf("2nd pwm set to %.2f %%\n\r", green_pwm.read() * 100); } if(a =='d') { - printf("Exiting loop"); + printf("Exiting loop\n\r"); loop=0; } } @@ -192,34 +192,34 @@ uint8_t count_dir = UP; while(loop==1) { - printf("Enter d to exit loop"); + printf("Enter d to exit loop\n\r"); char a = pc.getc(); for(int i=0; i<10; i++) { if(count_dir == UP) { - ndpwm = ndpwm + 0.1; - rdpwm = rdpwm + 0.1; - if(ndpwm == 1.00) + red_pwm = red_pwm + 0.1; + green_pwm = green_pwm + 0.1; + if(red_pwm == 1.00) { // if hit one, start counting down count_dir = DOWN; } } else if(count_dir == DOWN) { - ndpwm = ndpwm - 0.1; - rdpwm = rdpwm - 0.1; + red_pwm = red_pwm - 0.1; + green_pwm = green_pwm - 0.1; if(mypwm == 0.0) { // if hit zero, start counting up count_dir = UP; } } - printf("pwm set to %.2f %%\n\r", rdpwm.read() * 100); - printf("2nd pwm set to %.2f %%\n", ndpwm.read() * 100); + printf("pwm set to %.2f %%\n\r", green_pwm.read() * 100); + printf("2nd pwm set to %.2f %%\n\r", red_pwm.read() * 100); } if(a =='d') { - printf("Exiting loop"); + printf("Exiting loop\n\r"); loop=0; } } @@ -229,15 +229,15 @@ uint8_t count_dir = UP; while(loop==1) { - printf("Enter d to exit loop"); + printf("Enter d to exit loop\n\r"); char a = pc.getc(); for(int i=0; i<10; i++) { if(count_dir == UP) { - rdpwm = rdpwm + 0.1; - ndpwm = ndpwm + 0.1; + green_pwm = green_pwm + 0.1; + red_pwm = red_pwm + 0.1; mypwm = mypwm + 0.1; if(mypwm == 1.00) { // if hit one, start counting down @@ -245,117 +245,116 @@ } } else if(count_dir == DOWN) { - ndpwm = ndpwm - 0.1; + red_pwm = red_pwm - 0.1; mypwm = mypwm - 0.1; - rdpwm = rdpwm - 0.1; + green_pwm = green_pwm - 0.1; if(mypwm == 0.0) { // if hit zero, start counting up count_dir = UP; } } printf("pwm set to %.2f %%\n\r", mypwm.read() * 100); - printf("2nd pwm set to %.2f %%\n", ndpwm.read() * 100); - printf("3rd pwm set to %.2f %%\n", rdpwm.read() * 100); + printf("2nd pwm set to %.2f %%\n\r", red_pwm.read() * 100); + printf("3rd pwm set to %.2f %%\n\r", green_pwm.read() * 100); } if(a =='d') { - printf("Exiting loop"); + printf("Exiting loop\n\r"); loop=0; } } } int main() { uint8_t loop=1; - uint8_t i; + uint8_t i; uint8_t count_dir; mypwm.period_ms(10); mypwm.pulsewidth_ms(1); - ndpwm.period_ms(10); - ndpwm.pulsewidth_ms(1); - rdpwm.period_ms(10); - rdpwm.pulsewidth_ms(1); - + red_pwm.period_ms(10); + red_pwm.pulsewidth_ms(1); + green_pwm.period_ms(10); + green_pwm.pulsewidth_ms(1); + count_dir = UP; - pc.printf("Press '7' for White, Press '6' for Orange, Press '5' for Yellow, Press '4' for Green, Press '3' for Red, Press '2 for Purple, Press '1' for Blue, '0' to turn it OFF\n"); - while(loop== 1) { + pc.printf("Press '7' for White, Press '6' for Orange, Press '5' for Yellow, Press '4' for Green, Press '3' for Red, Press '2 for Purple, Press '1' for Blue, '0' to turn it OFF\n\r"); + while(loop== 1) { + /* mypwm=0; - ndpwm=0; - rdpwm=0; + red_pwm=0; + green_pwm=0; + */ char c = pc.getc(); // Read hyperterminal + if (c == 'o') { - mypwm=0; - ndpwm=0; - rdpwm=0; + mypwm=0; + red_pwm=0; + green_pwm=0; } - if (c == '1') - { - - // ON - while(c=='1') - { - glow_blue(); - c=0; - } - } - - if (c == '2') { - - // ON - while(c=='2') - { - glow_purple(); - c=0; - } + if (c == '1') { + + // ON + while(c=='1') { + glow_blue(); + c=0; } - if (c == '3') { - - // ON - while(c=='3') - { - glow_red(); - c=0; - } - } - if (c == '4') { - - // ON - while(c=='4') - { - glow_green(); - c=0; - } - } - if (c == '5') { - - // ON - while(c=='5') - { - glow_yellow(); - c=0; - } - } - if (c == '6') { - - // ON - while(c=='6') - { - glow_orange(); - c=0; - } - } - if (c == '7') { - - // ON - while(c=='7') - { - glow_white(); - c=0; - } - } - if( c== 'f'){ - loop=0; - } } + if (c == '2') { + + // ON + while(c=='2') { + glow_purple(); + c=0; + } + } + if (c == '3') { + + // ON + while(c=='3') { + glow_red(); + c=0; + } + } + if (c == '4') { + + // ON + while(c=='4') { + glow_green(); + c=0; + } + } + if (c == '5') { + + // ON + while(c=='5') { + glow_yellow(); + c=0; + } + } + if (c == '6') { + + // ON + while(c=='6') { + glow_orange(); + c=0; + } + } + if (c == '7') { + + // ON + while(c=='7') { + glow_white(); + c=0; + } + } + if( c== 'f') { + loop=0; + } + if (c == 'h'){ + pc.printf("Press '7' for White, Press '6' for Orange, Press '5' for Yellow, Press '4' for Green, Press '3' for Red, Press '2 for Purple, Press '1' for Blue, '0' to turn it OFF\n\r"); + } + } +} +