John's code modified for envelope shaping and different colours

Dependencies:   mbed

Fork of Morse-buddy-JohnF by Tony Abbey

Files at this revision

API Documentation at this revision

Comitter:
tony1tf
Date:
Thu Jun 27 10:52:29 2013 +0000
Parent:
1:ba9c803c7596
Child:
3:cbd036b6942b
Commit message:
Audio envelope shaping and changing coloured LED added

Changed in this revision

Morse_Code.cpp Show annotated file Show diff for this revision Revisions of this file
Morse_Code.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/Morse_Code.cpp	Sat Jun 22 23:13:14 2013 +0000
+++ b/Morse_Code.cpp	Thu Jun 27 10:52:29 2013 +0000
@@ -2,7 +2,7 @@
 //==============================================================
 //  Morse Code  June 30, 2011  John H. Fisher - K5JHF
 //==============================================================
-// mods by Tony Abbey for envelope shaping - 22 June 2013
+// mods by Tony Abbey for envelope shaping and coloured LEDs - 27 June 2013
 
 #include "mbed.h"
 
@@ -12,38 +12,38 @@
 
 const float sine_wave [ 32 ]    =   {
     
-    sin (  1 * step ) / 2.0 + 0.5 ,
-    sin (  2 * step ) / 2.0 + 0.5 ,
-    sin (  3 * step ) / 2.0 + 0.5 ,
-    sin (  4 * step ) / 2.0 + 0.5 ,
-    sin (  5 * step ) / 2.0 + 0.5 ,
-    sin (  6 * step ) / 2.0 + 0.5 ,
-    sin (  7 * step ) / 2.0 + 0.5 ,
-    sin (  8 * step ) / 2.0 + 0.5 ,
-    sin (  9 * step ) / 2.0 + 0.5 ,
-    sin ( 10 * step ) / 2.0 + 0.5 ,
-    sin ( 11 * step ) / 2.0 + 0.5 ,
-    sin ( 12 * step ) / 2.0 + 0.5 ,
-    sin ( 13 * step ) / 2.0 + 0.5 ,
-    sin ( 14 * step ) / 2.0 + 0.5 ,
-    sin ( 15 * step ) / 2.0 + 0.5 ,
-    sin ( 16 * step ) / 2.0 + 0.5 ,
-    sin ( 17 * step ) / 2.0 + 0.5 ,
-    sin ( 18 * step ) / 2.0 + 0.5 ,
-    sin ( 19 * step ) / 2.0 + 0.5 ,
-    sin ( 20 * step ) / 2.0 + 0.5 ,
-    sin ( 21 * step ) / 2.0 + 0.5 ,
-    sin ( 22 * step ) / 2.0 + 0.5 ,
-    sin ( 23 * step ) / 2.0 + 0.5 ,
-    sin ( 24 * step ) / 2.0 + 0.5 ,
-    sin ( 25 * step ) / 2.0 + 0.5 ,
-    sin ( 26 * step ) / 2.0 + 0.5 ,
-    sin ( 27 * step ) / 2.0 + 0.5 ,
-    sin ( 28 * step ) / 2.0 + 0.5 ,
-    sin ( 29 * step ) / 2.0 + 0.5 ,
-    sin ( 30 * step ) / 2.0 + 0.5 ,
-    sin ( 31 * step ) / 2.0 + 0.5 ,
-    sin (  0 * step ) / 2.0 + 0.5 
+    sin (  1 * step ) / 2.5 ,
+    sin (  2 * step ) / 2.5 ,
+    sin (  3 * step ) / 2.5 ,
+    sin (  4 * step ) / 2.5 ,
+    sin (  5 * step ) / 2.5 ,
+    sin (  6 * step ) / 2.5 ,
+    sin (  7 * step ) / 2.5 ,
+    sin (  8 * step ) / 2.5 ,
+    sin (  9 * step ) / 2.5 ,
+    sin ( 10 * step ) / 2.5 ,
+    sin ( 11 * step ) / 2.5 ,
+    sin ( 12 * step ) / 2.5 ,
+    sin ( 13 * step ) / 2.5 ,
+    sin ( 14 * step ) / 2.5 ,
+    sin ( 15 * step ) / 2.5 ,
+    sin ( 16 * step ) / 2.5 ,
+    sin ( 17 * step ) / 2.5 ,
+    sin ( 18 * step ) / 2.5 ,
+    sin ( 19 * step ) / 2.5 ,
+    sin ( 20 * step ) / 2.5 ,
+    sin ( 21 * step ) / 2.5 ,
+    sin ( 22 * step ) / 2.5 ,
+    sin ( 23 * step ) / 2.5 ,
+    sin ( 24 * step ) / 2.5 ,
+    sin ( 25 * step ) / 2.5 ,
+    sin ( 26 * step ) / 2.5 ,
+    sin ( 27 * step ) / 2.5 ,
+    sin ( 28 * step ) / 2.5 ,
+    sin ( 29 * step ) / 2.5 ,
+    sin ( 30 * step ) / 2.5 ,
+    sin ( 31 * step ) / 2.5 ,
+    sin (  0 * step ) / 2.5 
 
     };
 
@@ -51,9 +51,8 @@
 
         Morse_Code::Morse_Code  (   float  WPM_Character,
                                     float  WPM_Speed,
-                                    int    Tone_Frequency,
-                                    char   LED_Pin,
-                                    char   Speaker_Pin  )  {
+                                    int    Tone_Frequency,  
+                                    char   colour )  {
    
             _WPM_Character  =  WPM_Character;
 
@@ -61,9 +60,7 @@
            
             _Tone_Frequency =  Tone_Frequency;
             
-            _LED_Pin        =  LED_Pin;
-            
-            _Speaker_Pin    =  Speaker_Pin;
+            _colour            =  colour;
 
             Calculate_Morse_Timing ( _WPM_Speed, _WPM_Character );
   
@@ -552,11 +549,14 @@
 
 void  Morse_Code::dit  ( )  {
   
-    led =   on;
+    if ( _colour == 1 ) blue =   on;
+    if ( _colour == 2 ) red = on;
+    if ( _colour == 3 ) green = on;
+    if ( _colour == 4 ) blue = on red = on green = on ;
 
     Tone ( _Tone_Frequency, u, 1.0 );
 
-    led =   off;
+    blue = off red = off green = off ;
   
    }
   
@@ -564,11 +564,14 @@
 
 void  Morse_Code::dah  ( )  {
 
-    led =   on;
+    if ( _colour == 1 ) blue = on;
+    if ( _colour == 2 ) red = on;
+    if ( _colour == 3 ) green = on;
+    if ( _colour == 4 ) blue = on red = on green = on ;
 
     Tone ( _Tone_Frequency, u, 3.0 );
 
-    led =   off;
+       blue = off red = off green = off ;
   
     }
   
@@ -592,13 +595,13 @@
     
         for ( i = 0; i < 32; i++ )  {
 
-            piezo  =   sine_wave [ i ] * amplitude;
+            piezo  =   sine_wave [ i ] * amplitude + 0.4;
     
             for ( delay = 0; delay < freq_factor; delay++ );  
 
             } t = timer.read() ;
-             if ( t < duration/7 ) amplitude = t * 7 / duration ;
-             if ( t/multiplier > duration * 0.85 ) amplitude = ( ( duration - t/multiplier ) / duration  ) * 8.5 ;
+             if ( t < duration/5 ) amplitude = t * 5 / duration ;
+             if ( t/multiplier > duration * 0.8 ) amplitude = ( ( duration - t/multiplier ) / duration  ) * 8 ;
 
         } while ( timer.read() < duration * multiplier );
 
--- a/Morse_Code.h	Sat Jun 22 23:13:14 2013 +0000
+++ b/Morse_Code.h	Thu Jun 27 10:52:29 2013 +0000
@@ -2,7 +2,7 @@
 //==============================================================
 //  Morse Code  June 30, 2011  John H. Fisher - K5JHF
 //==============================================================
-// Mods for envelope shaping - Tony Abbey 22 June 2013
+// Mods for envelope shaping and different coloured LEDs - Tony Abbey 27 June 2013
 
 #ifndef  MORSE_CODE_H
 #define  MORSE_CODE_H
@@ -25,7 +25,8 @@
 
     int    _Tone_Frequency;
     
-    char   _LED_Pin,  _Speaker_Pin;
+    char    _colour ;
+
 
 //===================================================================
 
@@ -47,9 +48,8 @@
     
         Morse_Code  (   float  WPM_Character  = 18.0,
                         float  WPM_Speed      =  5.0,
-                        int    Tone_Frequency =  700,
-                        char   LED_Pin        =   11,
-                        char   Speaker_Pin    =    9  );
+                        int    Tone_Frequency =  700, 
+                        char   colour = 1 );
                         
         void    Sound_On ( void );                
 
--- a/main.cpp	Sat Jun 22 23:13:14 2013 +0000
+++ b/main.cpp	Thu Jun 27 10:52:29 2013 +0000
@@ -2,23 +2,24 @@
 #include "main.h"
 #include "Morse_Code.h"
 
-DigitalOut  led     ( LED_BLUE );
+DigitalOut  blue     ( LED_BLUE );
+DigitalOut  red     ( LED_RED );
+DigitalOut  green     ( LED_GREEN );
+
 
 AnalogOut   piezo   ( PTE30 );
 
-Morse_Code  A   =   Morse_Code ( 18.0, 10.0, 400, 9, 11 );
+Morse_Code  A   =   Morse_Code ( 18.0, 10.0, 400, 1 );
 
-Morse_Code  B   =   Morse_Code ( 18.0, 15.0, 350, 9, 11 );
+Morse_Code  B   =   Morse_Code ( 18.0, 15.0, 350, 2 );
 
-Morse_Code  C   =   Morse_Code ( 18.0, 20.0, 300, 9, 11 );
+Morse_Code  C   =   Morse_Code ( 18.0, 20.0, 300, 3 );
 
-Morse_Code  D   =   Morse_Code ( 18.0, 30.0, 250, 9, 11 );
+Morse_Code  D   =   Morse_Code ( 18.0, 30.0, 250, 4 );
 
 int main() {
 
     int i;
-
-    led     =   off;
   
     while(1) {
 
--- a/main.h	Sat Jun 22 23:13:14 2013 +0000
+++ b/main.h	Thu Jun 27 10:52:29 2013 +0000
@@ -4,8 +4,9 @@
 #define on  0;
 #define off 1;
 
-extern  DigitalOut led;
-
+extern  DigitalOut blue;
+extern  DigitalOut green;
+extern  DigitalOut red;
 extern  AnalogOut piezo;
 
 #endif
\ No newline at end of file