Test program using the LCD and touch pad to adjust the Analog output DAC on the KL46Z Port PTE30

Dependencies:   SLCD TSI mbed

Fork of keyer_test_v3 by Stanley Cohen

Committer:
scohennm
Date:
Thu Apr 23 01:56:30 2015 +0000
Revision:
3:dd70474b11bc
Parent:
2:86fa1f84db36
Test of DAC out using cap slider

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scohennm 2:86fa1f84db36 1 #include "mbed.h"
scohennm 2:86fa1f84db36 2 #include "SLCD.h"
scohennm 2:86fa1f84db36 3 #include "TSISensor.h"
scohennm 2:86fa1f84db36 4
scohennm 2:86fa1f84db36 5 //Code parameters
scohennm 2:86fa1f84db36 6
scohennm 2:86fa1f84db36 7 #define LCDLEN 10
scohennm 2:86fa1f84db36 8 //LCD messages
scohennm 2:86fa1f84db36 9 #define VOLTAST 0
scohennm 2:86fa1f84db36 10 #define VOLTMESS "V:"
scohennm 2:86fa1f84db36 11 #define DATARATE 0.1 // sec
scohennm 2:86fa1f84db36 12 #define MAXVOLTS 3.3
scohennm 2:86fa1f84db36 13 #define FUTURESTATE 1
scohennm 2:86fa1f84db36 14
scohennm 2:86fa1f84db36 15 SLCD slcd; //define LCD display
scohennm 2:86fa1f84db36 16
scohennm 2:86fa1f84db36 17 //Global classes
scohennm 2:86fa1f84db36 18 TSISensor tsiScaling; // Capacitive sensor/slider
scohennm 2:86fa1f84db36 19 AnalogOut refOut(PTE30);
scohennm 2:86fa1f84db36 20 PwmOut led(LED_RED);
scohennm 2:86fa1f84db36 21
scohennm 2:86fa1f84db36 22 // Global scalars
scohennm 2:86fa1f84db36 23 char lcdData[LCDLEN];
scohennm 2:86fa1f84db36 24
scohennm 2:86fa1f84db36 25
scohennm 2:86fa1f84db36 26
scohennm 2:86fa1f84db36 27
scohennm 2:86fa1f84db36 28 void LCDMessNoDwell(char *lMess){
scohennm 2:86fa1f84db36 29 slcd.Home();
scohennm 2:86fa1f84db36 30 slcd.clear();
scohennm 2:86fa1f84db36 31 slcd.printf(lMess);
scohennm 2:86fa1f84db36 32 }
scohennm 2:86fa1f84db36 33
scohennm 2:86fa1f84db36 34
scohennm 2:86fa1f84db36 35
scohennm 2:86fa1f84db36 36 void parameterAdjust( int adjState, float scaling) { // small adjustment state machine
scohennm 2:86fa1f84db36 37 float tempFloat;
scohennm 2:86fa1f84db36 38 switch (adjState){
scohennm 2:86fa1f84db36 39 case VOLTAST: {
scohennm 2:86fa1f84db36 40 tempFloat = scaling;
scohennm 2:86fa1f84db36 41 refOut.write(tempFloat);
scohennm 2:86fa1f84db36 42 sprintf (lcdData,"%4.3f",tempFloat*MAXVOLTS);
scohennm 2:86fa1f84db36 43 break;
scohennm 2:86fa1f84db36 44 }
scohennm 2:86fa1f84db36 45 case FUTURESTATE: {
scohennm 2:86fa1f84db36 46 break;
scohennm 2:86fa1f84db36 47 }
scohennm 2:86fa1f84db36 48 }
scohennm 2:86fa1f84db36 49 LCDMessNoDwell(lcdData);
scohennm 2:86fa1f84db36 50 return;
scohennm 2:86fa1f84db36 51 }
scohennm 2:86fa1f84db36 52
scohennm 2:86fa1f84db36 53 int main(){
scohennm 2:86fa1f84db36 54
scohennm 2:86fa1f84db36 55 float tempValue;
scohennm 2:86fa1f84db36 56
scohennm 2:86fa1f84db36 57 parameterAdjust( VOLTAST, 0.0);
scohennm 2:86fa1f84db36 58
scohennm 2:86fa1f84db36 59
scohennm 2:86fa1f84db36 60 while (true) {
scohennm 2:86fa1f84db36 61 tempValue = tsiScaling.readPercentage();
scohennm 2:86fa1f84db36 62 if(tempValue > 0) {
scohennm 2:86fa1f84db36 63 parameterAdjust( VOLTAST, tempValue);
scohennm 2:86fa1f84db36 64 }
scohennm 2:86fa1f84db36 65
scohennm 2:86fa1f84db36 66 wait(DATARATE);
scohennm 2:86fa1f84db36 67 } // while forever
scohennm 2:86fa1f84db36 68 }// end main