KBrat-SSD645-HW-1_1

Dependencies:   SLCD TSI mbed

Fork of kl46z_btn_slider_toSerial by Stanley Cohen

Committer:
tisbrat
Date:
Mon Jan 23 15:47:30 2017 +0000
Revision:
8:431c6c45db8b
Parent:
7:8f64ad5334ca
KBrat-SSD645-HW-1_1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scohennm 0:e23fffd4b9a7 1 #include "mbed.h"
scohennm 6:a109f45fae66 2 #include "SLCD.h"
scohennm 6:a109f45fae66 3 #include "TSISensor.h"
scohennm 6:a109f45fae66 4
scohennm 2:b49e5adf84df 5
scohennm 0:e23fffd4b9a7 6 #define LEDON false
scohennm 0:e23fffd4b9a7 7 #define LEDOFF true
scohennm 1:2688f68df85d 8 #define NUMBUTS 2
scohennm 6:a109f45fae66 9 #define RBUTINDEX 0
scohennm 6:a109f45fae66 10 #define LBUTINDEX 1
scohennm 3:7e9670be412e 11 #define LBUT PTC12 // port addresses for buttons
scohennm 1:2688f68df85d 12 #define RBUT PTC3
sim1sgl 7:8f64ad5334ca 13 #define DATATIME 200 //milliseconds
scohennm 6:a109f45fae66 14 #define LCDLEN 10
sim1sgl 7:8f64ad5334ca 15 #define PROGNAME "kl46z_btn_slider_toSerial\r\n"
scohennm 3:7e9670be412e 16
scohennm 6:a109f45fae66 17 // Cap slider interface
scohennm 6:a109f45fae66 18 SLCD slcd; //define LCD display
scohennm 6:a109f45fae66 19
scohennm 6:a109f45fae66 20 TSISensor tsiScaling; // Capacitive sensor/slider
scohennm 6:a109f45fae66 21 Timer dataTimer;
scohennm 0:e23fffd4b9a7 22
scohennm 6:a109f45fae66 23 // Button interrrupts
sim1sgl 7:8f64ad5334ca 24 InterruptIn rtButton(RBUT);
scohennm 6:a109f45fae66 25 InterruptIn lfButton(LBUT);
scohennm 3:7e9670be412e 26
scohennm 6:a109f45fae66 27 char lcdData[LCDLEN];
scohennm 6:a109f45fae66 28
sim1sgl 7:8f64ad5334ca 29 Serial pc(USBTX, USBRX);// set up USB as communications to Host PC via USB connectons
scohennm 3:7e9670be412e 30
scohennm 6:a109f45fae66 31 // Interrupt service routines
scohennm 6:a109f45fae66 32 void rtButtonPressed(){
sim1sgl 7:8f64ad5334ca 33 pc.printf("button: right\r\n");
scohennm 6:a109f45fae66 34 }
scohennm 6:a109f45fae66 35
scohennm 6:a109f45fae66 36 void lfButtonPressed(){
sim1sgl 7:8f64ad5334ca 37 pc.printf("button: left \r\n");
scohennm 6:a109f45fae66 38 }
scohennm 6:a109f45fae66 39
scohennm 6:a109f45fae66 40 // End interrupt routines
scohennm 6:a109f45fae66 41
scohennm 6:a109f45fae66 42 // Regular routines
scohennm 6:a109f45fae66 43 void LCDMessNoDwell(char *lMess){
scohennm 6:a109f45fae66 44 slcd.Home();
scohennm 6:a109f45fae66 45 slcd.clear();
scohennm 6:a109f45fae66 46 slcd.printf(lMess);
scohennm 6:a109f45fae66 47 }
scohennm 6:a109f45fae66 48
scohennm 1:2688f68df85d 49 // --------------------------------
scohennm 3:7e9670be412e 50 int main() {
tisbrat 8:431c6c45db8b 51 //float sliderValue = 0.0;
sim1sgl 7:8f64ad5334ca 52 float sliderValue = 0.0;
scohennm 2:b49e5adf84df 53
sim1sgl 7:8f64ad5334ca 54 pc.printf(PROGNAME);
scohennm 6:a109f45fae66 55 dataTimer.start();
scohennm 6:a109f45fae66 56 dataTimer.reset();
scohennm 6:a109f45fae66 57 sprintf (lcdData,"%4.3f",0.0);
scohennm 6:a109f45fae66 58 LCDMessNoDwell(lcdData);
scohennm 6:a109f45fae66 59
scohennm 6:a109f45fae66 60 // Interrupt routine setups
scohennm 6:a109f45fae66 61 rtButton.fall(&rtButtonPressed);
scohennm 6:a109f45fae66 62 lfButton.fall(&lfButtonPressed);
scohennm 6:a109f45fae66 63
scohennm 3:7e9670be412e 64 // End of setup
scohennm 3:7e9670be412e 65
scohennm 0:e23fffd4b9a7 66 while(true) {
sim1sgl 7:8f64ad5334ca 67 // All the interrupts
scohennm 6:a109f45fae66 68
scohennm 6:a109f45fae66 69 if (dataTimer.read_ms() > DATATIME){
sim1sgl 7:8f64ad5334ca 70 // Read the slider value
sim1sgl 7:8f64ad5334ca 71 float newSliderValue = tsiScaling.readPercentage();
sim1sgl 7:8f64ad5334ca 72 // Only do stuff with it if it's a new value or if it's not zero
sim1sgl 7:8f64ad5334ca 73 if(newSliderValue > 0.0 && newSliderValue != sliderValue) {
sim1sgl 7:8f64ad5334ca 74 sliderValue = newSliderValue;
tisbrat 8:431c6c45db8b 75 //sprintf (lcdData,"%4.3f", sliderValue); // Just to make things user readable
tisbrat 8:431c6c45db8b 76 sprintf (lcdData,"%4.3f", sliderValue+1000); // Just to make things user readable
sim1sgl 7:8f64ad5334ca 77
scohennm 6:a109f45fae66 78 LCDMessNoDwell(lcdData);
sim1sgl 7:8f64ad5334ca 79 pc.printf("slider: %4.3f\r\n", sliderValue);
scohennm 6:a109f45fae66 80 }
scohennm 6:a109f45fae66 81 dataTimer.reset();
scohennm 6:a109f45fae66 82 }
scohennm 6:a109f45fae66 83
scohennm 0:e23fffd4b9a7 84 }
scohennm 0:e23fffd4b9a7 85 }