Siphamandla Simelane / Mbed 2 deprecated slider_diatonic_SP

Dependencies:   SLCD TSI mbed

Fork of slider_diatonic_v1 by Vishal Bharam

Files at this revision

API Documentation at this revision

Comitter:
scohennm
Date:
Tue Dec 16 03:14:27 2014 +0000
Child:
1:6f0197189fcc
Commit message:
Simple Iambic keyer. KL46Z speed select via capacitive slider.

Changed in this revision

SLCD.lib Show annotated file Show diff for this revision Revisions of this file
TSI.lib Show annotated file Show diff for this revision Revisions of this file
keyer_test_v3.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SLCD.lib	Tue Dec 16 03:14:27 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Tue Dec 16 03:14:27 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/keyer_test_v3.cpp	Tue Dec 16 03:14:27 2014 +0000
@@ -0,0 +1,151 @@
+#include "mbed.h"
+#include "SLCD.h"
+#include "TSISensor.h"
+
+#define BASESPEED   1.200
+#define DOT         1
+#define DASH        3
+#define INTERCHAR   3
+#define CHANNELON   0
+#define CHANNELOFF  1
+#define LCDLEN      10
+#define DOTMESS     "DIT"
+#define DASHMESS    "DAH"
+#define IAMMESS     "IAMB"
+#define NULLMESS    "111"  // LCD idle message
+#define FIXEDWPM    13
+#define LOWSPEED   5
+#define SPPEDINT    25.0 // This gives a max speed of 30 - 5 + 25
+
+#define STATECOEF   2
+#define IDLE        0
+#define DIT         1
+#define DAH         2
+#define IAM         3
+
+SLCD slcd; //define LCD display
+// keyer test
+TSISensor tsiScaling; // Capacitive sensor/slider
+DigitalIn RtButton(PTC12);
+DigitalIn LftButton(PTC3);
+DigitalIn DahPaddle(PTD7);
+DigitalIn DitPaddle(PTD6);
+DigitalOut led(LED_RED);
+DigitalOut outPin(PTC9); //J1-16
+int KeyState = IDLE;
+
+
+void LCDMessNoDwell(char *lMess){
+        slcd.Home();
+        slcd.clear();
+        slcd.printf(lMess);
+} 
+
+void makeDit (float dotLen,DigitalOut outChannel, DigitalOut cloneChannel) {
+    outChannel.write(CHANNELON);
+    cloneChannel.write(CHANNELON);
+    wait(dotLen);
+    outChannel.write(CHANNELOFF);
+    cloneChannel.write(CHANNELOFF);
+    wait(float(DOT)*dotLen);
+    return;
+}
+    
+void makeDah (float dotLen,DigitalOut outChannel, DigitalOut cloneChannel) {
+    outChannel.write(CHANNELON);
+    cloneChannel.write(CHANNELON);
+    wait(float(DASH)*dotLen);
+    outChannel.write(CHANNELOFF);
+    cloneChannel.write(CHANNELOFF);
+    wait(float(DOT)*dotLen);
+    return;
+}
+
+
+int main(){
+    int wpm = FIXEDWPM;
+    float elementLen;  // period in seconds
+    int RButtonState;
+    int LButtonState;
+    int DahPaddleState;
+    int DitPaddleState;
+    char lcdData[LCDLEN];
+    float tempValue;
+    int lastKeyHit = DIT;
+    
+    
+    elementLen = BASESPEED / (float) wpm;
+    
+    led.write(CHANNELOFF);
+    outPin.write(CHANNELOFF);
+    sprintf (lcdData,"%d",wpm);
+    LCDMessNoDwell(lcdData);
+    
+    
+    while (true) {
+    /*
+        RButtonState = !RtButton.read(); // button is pulled up so false is when button is pushed it's inverted to avoid confusion downstream
+        if (RButtonState){
+           KeyState = DAH;  
+        }
+        LButtonState = !LftButton.read();
+        if (LButtonState) {
+            KeyState = DIT;
+        }        
+    */
+       RButtonState = !RtButton.read();
+       LButtonState = !LftButton.read();
+       DahPaddleState =!DahPaddle.read();
+       DitPaddleState = !DitPaddle.read();
+       KeyState = LButtonState + STATECOEF*RButtonState;
+       KeyState = KeyState + DitPaddleState + STATECOEF*DahPaddleState;
+        
+        switch (KeyState) {
+            case DAH:{
+                LCDMessNoDwell(DASHMESS);
+                makeDah(elementLen,outPin,led);
+                KeyState = IDLE; 
+                lastKeyHit = DAH;
+                sprintf (lcdData,"%d",wpm);
+                LCDMessNoDwell(lcdData); 
+                break;     
+            }
+            case DIT:{
+                LCDMessNoDwell(DOTMESS);
+                makeDit(elementLen,outPin,led);             
+                KeyState = IDLE;
+                lastKeyHit = DIT;
+                sprintf (lcdData,"%d",wpm);
+                LCDMessNoDwell(lcdData); 
+                break;
+            }
+            case IAM:{
+                LCDMessNoDwell(IAMMESS);
+                if (lastKeyHit == DAH){;
+                    makeDit(elementLen,outPin,led);  
+                    makeDah( elementLen,outPin,led);
+                    lastKeyHit = DAH;  
+                }  else {
+                    makeDah(elementLen,outPin,led);  
+                    makeDit(elementLen,outPin,led);
+                    lastKeyHit = DIT;  
+                }      
+                KeyState = IDLE;
+                sprintf (lcdData,"%d",wpm);
+                LCDMessNoDwell(lcdData); 
+                break;
+            }
+            case IDLE:{
+                tempValue = tsiScaling.readPercentage();
+                if(tempValue > 0) {
+                    wpm =  LOWSPEED + int(tempValue * SPPEDINT);
+                    elementLen = BASESPEED / (float) wpm;
+                    sprintf (lcdData,"%d",wpm);
+                    LCDMessNoDwell(lcdData);
+                }             
+                break;
+            }
+        } 
+         
+    } // while forever
+}// end main
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Dec 16 03:14:27 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file