Mrodr-SSD645-HW-1

Dependencies:   SLCD TSI mbed

Fork of kl46z_btn_slider_toSerial by Stanley Cohen

Committer:
mireyarod23
Date:
Mon Feb 06 05:00:32 2017 +0000
Revision:
9:3761e140b7a6
Parent:
8:258608fb0ffb
Rounding number up

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