final project update

Dependencies:   mbed

Fork of DISCO_SMT32L4_pwm_PB3 by Josh Blackann

Revision:
5:620125c08317
Parent:
4:9d26d117fa69
Child:
6:57bad75ec95b
--- a/main.cpp	Tue Apr 17 21:04:18 2018 +0000
+++ b/main.cpp	Thu Apr 19 22:54:33 2018 +0000
@@ -1,5 +1,5 @@
 #include "mbed.h"
-
+Serial pc(SERIAL_TX, SERIAL_RX);
 PwmOut mypwm(PWM_OUT);
 PwmOut ndpwm(LED1);
 PwmOut rdpwm(JOYSTICK_LEFT);
@@ -8,55 +8,354 @@
 #define UP 1
 #define DOWN 2
 
-int main() {
-    
-    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);
-    
-    printf("pwm set to %.2f %%\n", mypwm.read() * 100);
-    printf("2nd pwm set to %.2f %%\n", ndpwm.read() * 100);
-    printf("3rd pwm set to %.2f %%\n", rdpwm.read() * 100);
-    
-    count_dir = UP;
-    while(1) {
+ 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) 
+            {
 
-        for(i = 0; i < 10; i++ )
-        {
-            wait(0.1);
-            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) 
             {
-                rdpwm = rdpwm + 0.5;
-                ndpwm = ndpwm + 0.25;
-                mypwm = mypwm + 0.01;
-                if(mypwm == 1.00) // if hit one, start counting 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;
+                }
             }
-            else if(count_dir == DOWN)
+            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.5;
-                ndpwm = ndpwm - 0.25;
-                mypwm = mypwm - 0.01;
-                if(mypwm == 0.0)    // if hit zero, start counting up
-                {
+                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);
         }
-        printf("pwm set to %.2f %%\n\r", mypwm.read() * 100);
-        printf("2nd pwm set to %.2f %%\n\r", ndpwm.read() * 100);
-        printf("3rd pwm set to %.2f %%\n\r", rdpwm.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;
+             }
+        }
+
+    }
+