Test program using the LCD and touch pad to adjust the Analog output DAC on the KL46Z Port PTE30
Fork of keyer_test_v3 by
Revision 2:86fa1f84db36, committed 2015-02-10
- Comitter:
- scohennm
- Date:
- Tue Feb 10 21:15:22 2015 +0000
- Parent:
- 1:6f0197189fcc
- Child:
- 3:dd70474b11bc
- Commit message:
- Test program using the LCD and touch pad to adjust the Analog output DAC on the KL46Z Port PTE30
Changed in this revision
analgoutv1.cpp | Show annotated file Show diff for this revision Revisions of this file |
keyer_test_v3.cpp | Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/analgoutv1.cpp Tue Feb 10 21:15:22 2015 +0000 @@ -0,0 +1,74 @@ +#include "mbed.h" +#include "SLCD.h" +#include "TSISensor.h" + +//Code parameters + +#define LCDLEN 10 +//LCD messages +#define VOLTAST 0 +#define VOLTMESS "V:" +#define DATARATE 0.1 // sec +#define MAXVOLTS 3.3 +#define FUTURESTATE 1 + +SLCD slcd; //define LCD display + +//Global classes +TSISensor tsiScaling; // Capacitive sensor/slider +AnalogOut refOut(PTE30); +PwmOut led(LED_RED); + +// Global scalars +char lcdData[LCDLEN]; + + + + +void LCDMessNoDwell(char *lMess){ + slcd.Home(); + slcd.clear(); + slcd.printf(lMess); +} + + + +void parameterAdjust( int adjState, float scaling) { // small adjustment state machine + float tempFloat; + switch (adjState){ + case VOLTAST: { + tempFloat = scaling; + refOut.write(tempFloat); + sprintf (lcdData,"%4.3f",tempFloat*MAXVOLTS); + break; + } + case FUTURESTATE: { + /*toneFreq = TONEMIN + scaling * TONEINT; + tonePeriod = 1.0/toneFreq; + soundOut.period(tonePeriod); + tempInt = (int)toneFreq; + sprintf (lcdData,"%4d",tempInt); + */ + break; + } + } + LCDMessNoDwell(lcdData); + return; +} + +int main(){ + + float tempValue; + + parameterAdjust( VOLTAST, 0.0); + + + while (true) { + tempValue = tsiScaling.readPercentage(); + if(tempValue > 0) { + parameterAdjust( VOLTAST, tempValue); + } + + wait(DATARATE); + } // while forever +}// end main \ No newline at end of file
--- a/keyer_test_v3.cpp Fri Dec 19 16:34:51 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -#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 -#define SIDETONE 0.0014 //seconds -#define TONEON 0.50 -#define TONEOFF 0.0 - -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 -PwmOut soundOut(PTC9); -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); - soundOut.write(TONEON); - wait(dotLen); - outChannel.write(CHANNELOFF); - cloneChannel.write(CHANNELOFF); - soundOut.write(TONEOFF); - wait(float(DOT)*dotLen); - return; -} - -void makeDah (float dotLen,DigitalOut outChannel, DigitalOut cloneChannel) { - outChannel.write(CHANNELON); - cloneChannel.write(CHANNELON); - soundOut.write(TONEON); - wait(float(DASH)*dotLen); - outChannel.write(CHANNELOFF); - cloneChannel.write(CHANNELOFF); - soundOut.write(TONEOFF); - 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; - - soundOut.period(SIDETONE); - - - 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