final project update
Dependencies: mbed
Fork of DISCO_SMT32L4_pwm_PB3 by
main.cpp
- Committer:
- carter7778
- Date:
- 2018-04-19
- Revision:
- 5:620125c08317
- Parent:
- 4:9d26d117fa69
- Child:
- 6:57bad75ec95b
File content as of revision 5:620125c08317:
#include "mbed.h" Serial pc(SERIAL_TX, SERIAL_RX); PwmOut mypwm(PWM_OUT); PwmOut ndpwm(LED1); PwmOut rdpwm(JOYSTICK_LEFT); #define UP 1 #define DOWN 2 void glow_blue(void){ int loop=1; uint8_t count_dir = UP; while(loop==1) { printf("Enter d to exit loop"); char a = pc.getc(); for(int i=0; i<10; i++) { if(count_dir == UP) { mypwm = mypwm + 0.1; if(mypwm == 1.00) { // if hit one, start counting down count_dir = DOWN; } } else if(count_dir == DOWN) { mypwm = mypwm - 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); } if(a =='d') { printf("Exiting loop"); loop=0; } } } void glow_red(void){ int loop=1; uint8_t count_dir = UP; while(loop==1) { printf("Enter d to exit loop"); char a = pc.getc(); for(int i=0; i<10; i++) { if(count_dir == UP) { ndpwm = ndpwm + 0.1; if(ndpwm == 1.00) { // if hit one, start counting down count_dir = DOWN; } } else if(count_dir == DOWN) { ndpwm = ndpwm - 0.1; if(ndpwm == 0.0) { // if hit zero, start counting up count_dir = UP; } } printf("pwm set to %.2f %%\n\r", ndpwm.read() * 100); } if(a =='d') { printf("Exiting loop"); loop=0; } } } void glow_green(void){ int loop=1; uint8_t count_dir = UP; while(loop==1) { printf("Enter d to exit loop"); char a = pc.getc(); for(int i=0; i<10; i++) { if(count_dir == UP) { rdpwm = rdpwm + 0.1; if(rdpwm == 1.00) { // if hit one, start counting down count_dir = DOWN; } } else if(count_dir == DOWN) { rdpwm = rdpwm - 0.1; if(rdpwm == 0.0) { // if hit zero, start counting up count_dir = UP; } } printf("pwm set to %.2f %%\n\r", rdpwm.read() * 100); } if(a =='d') { printf("Exiting loop"); loop=0; } } } void glow_purple(void){ int loop=1; uint8_t count_dir = UP; while(loop==1) { printf("Enter d to exit loop"); char a = pc.getc(); for(int i=0; i<10; i++) { if(count_dir == UP) { ndpwm = ndpwm + 0.1; mypwm = mypwm + 0.1; if(mypwm == 1.00) { // if hit one, start counting down count_dir = DOWN; } } else if(count_dir == DOWN) { ndpwm = ndpwm - 0.1; mypwm = mypwm - 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); } if(a =='d') { printf("Exiting loop"); loop=0; } } } void glow_yellow(void){ int loop=1; uint8_t count_dir = UP; while(loop==1) { printf("Enter d to exit loop"); char a = pc.getc(); for(int i=0; i<10; i++) { if(count_dir == UP) { rdpwm = rdpwm + 0.1; mypwm = mypwm + 0.1; if(mypwm == 1.00) { // if hit one, start counting down count_dir = DOWN; } } else if(count_dir == DOWN) { rdpwm = rdpwm - 0.1; mypwm = mypwm - 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", rdpwm.read() * 100); } if(a =='d') { printf("Exiting loop"); loop=0; } } } void glow_orange(void){ int loop=1; uint8_t count_dir = UP; while(loop==1) { printf("Enter d to exit loop"); 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) { // if hit one, start counting down count_dir = DOWN; } } else if(count_dir == DOWN) { ndpwm = ndpwm - 0.1; rdpwm = rdpwm - 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); } if(a =='d') { printf("Exiting loop"); loop=0; } } } void glow_white(void){ int loop=1; uint8_t count_dir = UP; while(loop==1) { printf("Enter d to exit loop"); char a = pc.getc(); for(int i=0; i<10; i++) { if(count_dir == UP) { rdpwm = rdpwm + 0.1; ndpwm = ndpwm + 0.1; mypwm = mypwm + 0.1; if(mypwm == 1.00) { // if hit one, start counting down count_dir = DOWN; } } else if(count_dir == DOWN) { ndpwm = ndpwm - 0.1; mypwm = mypwm - 0.1; rdpwm = rdpwm - 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); } if(a =='d') { printf("Exiting loop"); loop=0; } } } int main() { uint8_t loop=1; 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); 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) { mypwm=0; ndpwm=0; rdpwm=0; char c = pc.getc(); // Read hyperterminal if (c == 'o') { mypwm=0; ndpwm=0; rdpwm=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 == '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; } } }