final project update

Dependencies:   mbed

Fork of DISCO_SMT32L4_pwm_PB3 by Josh Blackann

Committer:
carter7778
Date:
Thu Apr 19 22:54:33 2018 +0000
Revision:
5:620125c08317
Parent:
4:9d26d117fa69
Child:
6:57bad75ec95b
new code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:4860a91fb495 1 #include "mbed.h"
carter7778 5:620125c08317 2 Serial pc(SERIAL_TX, SERIAL_RX);
bcostm 0:4860a91fb495 3 PwmOut mypwm(PWM_OUT);
carter7778 4:9d26d117fa69 4 PwmOut ndpwm(LED1);
carter7778 4:9d26d117fa69 5 PwmOut rdpwm(JOYSTICK_LEFT);
bcostm 0:4860a91fb495 6
bcostm 0:4860a91fb495 7
jblackann 3:9aa9bfe031bb 8 #define UP 1
jblackann 3:9aa9bfe031bb 9 #define DOWN 2
jblackann 3:9aa9bfe031bb 10
carter7778 5:620125c08317 11 void glow_blue(void){
carter7778 5:620125c08317 12 int loop=1;
carter7778 5:620125c08317 13 uint8_t count_dir = UP;
carter7778 5:620125c08317 14 while(loop==1)
carter7778 5:620125c08317 15 {
carter7778 5:620125c08317 16 printf("Enter d to exit loop");
carter7778 5:620125c08317 17 char a = pc.getc();
carter7778 5:620125c08317 18 for(int i=0; i<10; i++)
carter7778 5:620125c08317 19 {
carter7778 5:620125c08317 20
carter7778 5:620125c08317 21 if(count_dir == UP)
carter7778 5:620125c08317 22 {
carter7778 4:9d26d117fa69 23
carter7778 5:620125c08317 24 mypwm = mypwm + 0.1;
carter7778 5:620125c08317 25 if(mypwm == 1.00)
carter7778 5:620125c08317 26 { // if hit one, start counting down
carter7778 5:620125c08317 27 count_dir = DOWN;
carter7778 5:620125c08317 28 }
carter7778 5:620125c08317 29 } else if(count_dir == DOWN)
jblackann 3:9aa9bfe031bb 30 {
carter7778 5:620125c08317 31 mypwm = mypwm - 0.1;
carter7778 5:620125c08317 32 if(mypwm == 0.0)
carter7778 5:620125c08317 33 { // if hit zero, start counting up
carter7778 5:620125c08317 34 count_dir = UP;
carter7778 5:620125c08317 35 }
carter7778 5:620125c08317 36 }
carter7778 5:620125c08317 37 printf("pwm set to %.2f %%\n\r", mypwm.read() * 100);
carter7778 5:620125c08317 38 }
carter7778 5:620125c08317 39
carter7778 5:620125c08317 40 if(a =='d') {
carter7778 5:620125c08317 41 printf("Exiting loop");
carter7778 5:620125c08317 42 loop=0;
carter7778 5:620125c08317 43 }
carter7778 5:620125c08317 44 }
carter7778 5:620125c08317 45 }
carter7778 5:620125c08317 46 void glow_red(void){
carter7778 5:620125c08317 47 int loop=1;
carter7778 5:620125c08317 48 uint8_t count_dir = UP;
carter7778 5:620125c08317 49 while(loop==1)
carter7778 5:620125c08317 50 {
carter7778 5:620125c08317 51 printf("Enter d to exit loop");
carter7778 5:620125c08317 52 char a = pc.getc();
carter7778 5:620125c08317 53 for(int i=0; i<10; i++)
carter7778 5:620125c08317 54 {
carter7778 5:620125c08317 55
carter7778 5:620125c08317 56 if(count_dir == UP)
carter7778 5:620125c08317 57 {
carter7778 5:620125c08317 58
carter7778 5:620125c08317 59 ndpwm = ndpwm + 0.1;
carter7778 5:620125c08317 60 if(ndpwm == 1.00)
carter7778 5:620125c08317 61 { // if hit one, start counting down
jblackann 3:9aa9bfe031bb 62 count_dir = DOWN;
jblackann 3:9aa9bfe031bb 63 }
carter7778 5:620125c08317 64 } else if(count_dir == DOWN)
carter7778 5:620125c08317 65 {
carter7778 5:620125c08317 66 ndpwm = ndpwm - 0.1;
carter7778 5:620125c08317 67 if(ndpwm == 0.0)
carter7778 5:620125c08317 68 { // if hit zero, start counting up
carter7778 5:620125c08317 69 count_dir = UP;
carter7778 5:620125c08317 70 }
jblackann 3:9aa9bfe031bb 71 }
carter7778 5:620125c08317 72 printf("pwm set to %.2f %%\n\r", ndpwm.read() * 100);
carter7778 5:620125c08317 73 }
carter7778 5:620125c08317 74
carter7778 5:620125c08317 75 if(a =='d') {
carter7778 5:620125c08317 76 printf("Exiting loop");
carter7778 5:620125c08317 77 loop=0;
carter7778 5:620125c08317 78 }
carter7778 5:620125c08317 79 }
carter7778 5:620125c08317 80 }
carter7778 5:620125c08317 81 void glow_green(void){
carter7778 5:620125c08317 82 int loop=1;
carter7778 5:620125c08317 83 uint8_t count_dir = UP;
carter7778 5:620125c08317 84 while(loop==1)
carter7778 5:620125c08317 85 {
carter7778 5:620125c08317 86 printf("Enter d to exit loop");
carter7778 5:620125c08317 87 char a = pc.getc();
carter7778 5:620125c08317 88 for(int i=0; i<10; i++)
carter7778 5:620125c08317 89 {
carter7778 5:620125c08317 90
carter7778 5:620125c08317 91 if(count_dir == UP)
carter7778 5:620125c08317 92 {
carter7778 5:620125c08317 93
carter7778 5:620125c08317 94 rdpwm = rdpwm + 0.1;
carter7778 5:620125c08317 95 if(rdpwm == 1.00)
carter7778 5:620125c08317 96 { // if hit one, start counting down
carter7778 5:620125c08317 97 count_dir = DOWN;
carter7778 5:620125c08317 98 }
carter7778 5:620125c08317 99 } else if(count_dir == DOWN)
jblackann 3:9aa9bfe031bb 100 {
carter7778 5:620125c08317 101 rdpwm = rdpwm - 0.1;
carter7778 5:620125c08317 102 if(rdpwm == 0.0)
carter7778 5:620125c08317 103 { // if hit zero, start counting up
carter7778 5:620125c08317 104 count_dir = UP;
carter7778 5:620125c08317 105 }
carter7778 5:620125c08317 106 }
carter7778 5:620125c08317 107 printf("pwm set to %.2f %%\n\r", rdpwm.read() * 100);
carter7778 5:620125c08317 108 }
carter7778 5:620125c08317 109
carter7778 5:620125c08317 110 if(a =='d') {
carter7778 5:620125c08317 111 printf("Exiting loop");
carter7778 5:620125c08317 112 loop=0;
carter7778 5:620125c08317 113 }
carter7778 5:620125c08317 114 }
carter7778 5:620125c08317 115 }
carter7778 5:620125c08317 116 void glow_purple(void){
carter7778 5:620125c08317 117 int loop=1;
carter7778 5:620125c08317 118 uint8_t count_dir = UP;
carter7778 5:620125c08317 119 while(loop==1)
carter7778 5:620125c08317 120 {
carter7778 5:620125c08317 121 printf("Enter d to exit loop");
carter7778 5:620125c08317 122 char a = pc.getc();
carter7778 5:620125c08317 123 for(int i=0; i<10; i++)
carter7778 5:620125c08317 124 {
carter7778 5:620125c08317 125
carter7778 5:620125c08317 126 if(count_dir == UP)
carter7778 5:620125c08317 127 {
carter7778 5:620125c08317 128 ndpwm = ndpwm + 0.1;
carter7778 5:620125c08317 129 mypwm = mypwm + 0.1;
carter7778 5:620125c08317 130 if(mypwm == 1.00)
carter7778 5:620125c08317 131 { // if hit one, start counting down
carter7778 5:620125c08317 132 count_dir = DOWN;
carter7778 5:620125c08317 133 }
carter7778 5:620125c08317 134 } else if(count_dir == DOWN)
carter7778 5:620125c08317 135 {
carter7778 5:620125c08317 136 ndpwm = ndpwm - 0.1;
carter7778 5:620125c08317 137 mypwm = mypwm - 0.1;
carter7778 5:620125c08317 138 if(mypwm == 0.0)
carter7778 5:620125c08317 139 { // if hit zero, start counting up
carter7778 5:620125c08317 140 count_dir = UP;
carter7778 5:620125c08317 141 }
carter7778 5:620125c08317 142 }
carter7778 5:620125c08317 143 printf("pwm set to %.2f %%\n\r", mypwm.read() * 100);
carter7778 5:620125c08317 144 printf("2nd pwm set to %.2f %%\n", ndpwm.read() * 100);
carter7778 5:620125c08317 145 }
carter7778 5:620125c08317 146
carter7778 5:620125c08317 147 if(a =='d') {
carter7778 5:620125c08317 148 printf("Exiting loop");
carter7778 5:620125c08317 149 loop=0;
carter7778 5:620125c08317 150 }
carter7778 5:620125c08317 151 }
carter7778 5:620125c08317 152 }
carter7778 5:620125c08317 153 void glow_yellow(void){
carter7778 5:620125c08317 154 int loop=1;
carter7778 5:620125c08317 155 uint8_t count_dir = UP;
carter7778 5:620125c08317 156 while(loop==1)
carter7778 5:620125c08317 157 {
carter7778 5:620125c08317 158 printf("Enter d to exit loop");
carter7778 5:620125c08317 159 char a = pc.getc();
carter7778 5:620125c08317 160 for(int i=0; i<10; i++)
carter7778 5:620125c08317 161 {
carter7778 5:620125c08317 162
carter7778 5:620125c08317 163 if(count_dir == UP)
carter7778 5:620125c08317 164 {
carter7778 5:620125c08317 165 rdpwm = rdpwm + 0.1;
carter7778 5:620125c08317 166 mypwm = mypwm + 0.1;
carter7778 5:620125c08317 167 if(mypwm == 1.00)
carter7778 5:620125c08317 168 { // if hit one, start counting down
carter7778 5:620125c08317 169 count_dir = DOWN;
carter7778 5:620125c08317 170 }
carter7778 5:620125c08317 171 } else if(count_dir == DOWN)
carter7778 5:620125c08317 172 {
carter7778 5:620125c08317 173 rdpwm = rdpwm - 0.1;
carter7778 5:620125c08317 174 mypwm = mypwm - 0.1;
carter7778 5:620125c08317 175 if(mypwm == 0.0)
carter7778 5:620125c08317 176 { // if hit zero, start counting up
jblackann 3:9aa9bfe031bb 177 count_dir = UP;
jblackann 3:9aa9bfe031bb 178 }
jblackann 3:9aa9bfe031bb 179 }
carter7778 5:620125c08317 180 printf("pwm set to %.2f %%\n\r", mypwm.read() * 100);
carter7778 5:620125c08317 181 printf("2nd pwm set to %.2f %%\n", rdpwm.read() * 100);
carter7778 5:620125c08317 182 }
carter7778 5:620125c08317 183
carter7778 5:620125c08317 184 if(a =='d') {
carter7778 5:620125c08317 185 printf("Exiting loop");
carter7778 5:620125c08317 186 loop=0;
carter7778 5:620125c08317 187 }
carter7778 5:620125c08317 188 }
carter7778 5:620125c08317 189 }
carter7778 5:620125c08317 190 void glow_orange(void){
carter7778 5:620125c08317 191 int loop=1;
carter7778 5:620125c08317 192 uint8_t count_dir = UP;
carter7778 5:620125c08317 193 while(loop==1)
carter7778 5:620125c08317 194 {
carter7778 5:620125c08317 195 printf("Enter d to exit loop");
carter7778 5:620125c08317 196 char a = pc.getc();
carter7778 5:620125c08317 197 for(int i=0; i<10; i++)
carter7778 5:620125c08317 198 {
carter7778 5:620125c08317 199
carter7778 5:620125c08317 200 if(count_dir == UP)
carter7778 5:620125c08317 201 {
carter7778 5:620125c08317 202 ndpwm = ndpwm + 0.1;
carter7778 5:620125c08317 203 rdpwm = rdpwm + 0.1;
carter7778 5:620125c08317 204 if(ndpwm == 1.00)
carter7778 5:620125c08317 205 { // if hit one, start counting down
carter7778 5:620125c08317 206 count_dir = DOWN;
carter7778 5:620125c08317 207 }
carter7778 5:620125c08317 208 } else if(count_dir == DOWN)
carter7778 5:620125c08317 209 {
carter7778 5:620125c08317 210 ndpwm = ndpwm - 0.1;
carter7778 5:620125c08317 211 rdpwm = rdpwm - 0.1;
carter7778 5:620125c08317 212 if(mypwm == 0.0)
carter7778 5:620125c08317 213 { // if hit zero, start counting up
carter7778 5:620125c08317 214 count_dir = UP;
carter7778 5:620125c08317 215 }
carter7778 5:620125c08317 216 }
carter7778 5:620125c08317 217 printf("pwm set to %.2f %%\n\r", rdpwm.read() * 100);
carter7778 5:620125c08317 218 printf("2nd pwm set to %.2f %%\n", ndpwm.read() * 100);
jblackann 3:9aa9bfe031bb 219 }
carter7778 5:620125c08317 220
carter7778 5:620125c08317 221 if(a =='d') {
carter7778 5:620125c08317 222 printf("Exiting loop");
carter7778 5:620125c08317 223 loop=0;
carter7778 5:620125c08317 224 }
carter7778 5:620125c08317 225 }
carter7778 5:620125c08317 226 }
carter7778 5:620125c08317 227 void glow_white(void){
carter7778 5:620125c08317 228 int loop=1;
carter7778 5:620125c08317 229 uint8_t count_dir = UP;
carter7778 5:620125c08317 230 while(loop==1)
carter7778 5:620125c08317 231 {
carter7778 5:620125c08317 232 printf("Enter d to exit loop");
carter7778 5:620125c08317 233 char a = pc.getc();
carter7778 5:620125c08317 234 for(int i=0; i<10; i++)
carter7778 5:620125c08317 235 {
carter7778 5:620125c08317 236
carter7778 5:620125c08317 237 if(count_dir == UP)
carter7778 5:620125c08317 238 {
carter7778 5:620125c08317 239 rdpwm = rdpwm + 0.1;
carter7778 5:620125c08317 240 ndpwm = ndpwm + 0.1;
carter7778 5:620125c08317 241 mypwm = mypwm + 0.1;
carter7778 5:620125c08317 242 if(mypwm == 1.00)
carter7778 5:620125c08317 243 { // if hit one, start counting down
carter7778 5:620125c08317 244 count_dir = DOWN;
carter7778 5:620125c08317 245 }
carter7778 5:620125c08317 246 } else if(count_dir == DOWN)
carter7778 5:620125c08317 247 {
carter7778 5:620125c08317 248 ndpwm = ndpwm - 0.1;
carter7778 5:620125c08317 249 mypwm = mypwm - 0.1;
carter7778 5:620125c08317 250 rdpwm = rdpwm - 0.1;
carter7778 5:620125c08317 251 if(mypwm == 0.0)
carter7778 5:620125c08317 252 { // if hit zero, start counting up
carter7778 5:620125c08317 253 count_dir = UP;
carter7778 5:620125c08317 254 }
carter7778 5:620125c08317 255 }
carter7778 5:620125c08317 256 printf("pwm set to %.2f %%\n\r", mypwm.read() * 100);
carter7778 5:620125c08317 257 printf("2nd pwm set to %.2f %%\n", ndpwm.read() * 100);
carter7778 5:620125c08317 258 printf("3rd pwm set to %.2f %%\n", rdpwm.read() * 100);
carter7778 5:620125c08317 259 }
carter7778 5:620125c08317 260
carter7778 5:620125c08317 261 if(a =='d') {
carter7778 5:620125c08317 262 printf("Exiting loop");
carter7778 5:620125c08317 263 loop=0;
carter7778 5:620125c08317 264 }
bcostm 0:4860a91fb495 265 }
bcostm 0:4860a91fb495 266 }
carter7778 5:620125c08317 267 int main() {
carter7778 5:620125c08317 268 uint8_t loop=1;
carter7778 5:620125c08317 269 uint8_t i;
carter7778 5:620125c08317 270 uint8_t count_dir;
carter7778 5:620125c08317 271 mypwm.period_ms(10);
carter7778 5:620125c08317 272 mypwm.pulsewidth_ms(1);
carter7778 5:620125c08317 273 ndpwm.period_ms(10);
carter7778 5:620125c08317 274 ndpwm.pulsewidth_ms(1);
carter7778 5:620125c08317 275 rdpwm.period_ms(10);
carter7778 5:620125c08317 276 rdpwm.pulsewidth_ms(1);
carter7778 5:620125c08317 277
carter7778 5:620125c08317 278 count_dir = UP;
carter7778 5:620125c08317 279 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");
carter7778 5:620125c08317 280 while(loop== 1) {
carter7778 5:620125c08317 281 mypwm=0;
carter7778 5:620125c08317 282 ndpwm=0;
carter7778 5:620125c08317 283 rdpwm=0;
carter7778 5:620125c08317 284 char c = pc.getc(); // Read hyperterminal
carter7778 5:620125c08317 285 if (c == 'o') {
carter7778 5:620125c08317 286 mypwm=0;
carter7778 5:620125c08317 287 ndpwm=0;
carter7778 5:620125c08317 288 rdpwm=0;
carter7778 5:620125c08317 289 }
carter7778 5:620125c08317 290 if (c == '1')
carter7778 5:620125c08317 291 {
carter7778 5:620125c08317 292
carter7778 5:620125c08317 293 // ON
carter7778 5:620125c08317 294 while(c=='1')
carter7778 5:620125c08317 295 {
carter7778 5:620125c08317 296 glow_blue();
carter7778 5:620125c08317 297 c=0;
carter7778 5:620125c08317 298 }
carter7778 5:620125c08317 299 }
carter7778 5:620125c08317 300
carter7778 5:620125c08317 301 if (c == '2') {
carter7778 5:620125c08317 302
carter7778 5:620125c08317 303 // ON
carter7778 5:620125c08317 304 while(c=='2')
carter7778 5:620125c08317 305 {
carter7778 5:620125c08317 306 glow_purple();
carter7778 5:620125c08317 307 c=0;
carter7778 5:620125c08317 308 }
carter7778 5:620125c08317 309 }
carter7778 5:620125c08317 310 if (c == '3') {
carter7778 5:620125c08317 311
carter7778 5:620125c08317 312 // ON
carter7778 5:620125c08317 313 while(c=='3')
carter7778 5:620125c08317 314 {
carter7778 5:620125c08317 315 glow_red();
carter7778 5:620125c08317 316 c=0;
carter7778 5:620125c08317 317 }
carter7778 5:620125c08317 318 }
carter7778 5:620125c08317 319 if (c == '4') {
carter7778 5:620125c08317 320
carter7778 5:620125c08317 321 // ON
carter7778 5:620125c08317 322 while(c=='4')
carter7778 5:620125c08317 323 {
carter7778 5:620125c08317 324 glow_green();
carter7778 5:620125c08317 325 c=0;
carter7778 5:620125c08317 326 }
carter7778 5:620125c08317 327 }
carter7778 5:620125c08317 328 if (c == '5') {
carter7778 5:620125c08317 329
carter7778 5:620125c08317 330 // ON
carter7778 5:620125c08317 331 while(c=='5')
carter7778 5:620125c08317 332 {
carter7778 5:620125c08317 333 glow_yellow();
carter7778 5:620125c08317 334 c=0;
carter7778 5:620125c08317 335 }
carter7778 5:620125c08317 336 }
carter7778 5:620125c08317 337 if (c == '6') {
carter7778 5:620125c08317 338
carter7778 5:620125c08317 339 // ON
carter7778 5:620125c08317 340 while(c=='6')
carter7778 5:620125c08317 341 {
carter7778 5:620125c08317 342 glow_orange();
carter7778 5:620125c08317 343 c=0;
carter7778 5:620125c08317 344 }
carter7778 5:620125c08317 345 }
carter7778 5:620125c08317 346 if (c == '7') {
carter7778 5:620125c08317 347
carter7778 5:620125c08317 348 // ON
carter7778 5:620125c08317 349 while(c=='7')
carter7778 5:620125c08317 350 {
carter7778 5:620125c08317 351 glow_white();
carter7778 5:620125c08317 352 c=0;
carter7778 5:620125c08317 353 }
carter7778 5:620125c08317 354 }
carter7778 5:620125c08317 355 if( c== 'f'){
carter7778 5:620125c08317 356 loop=0;
carter7778 5:620125c08317 357 }
carter7778 5:620125c08317 358 }
carter7778 5:620125c08317 359
carter7778 5:620125c08317 360 }
carter7778 5:620125c08317 361