Shane Barton
/
SBart_kl46z_btn_slider_toSerial_noDecimal
SSD 447 - HW 1.1
Fork of kl46z_btn_slider_toSerial by
main.cpp@8:f7063e4ba2c2, 2017-01-22 (annotated)
- Committer:
- sbart
- Date:
- Sun Jan 22 22:12:20 2017 +0000
- Revision:
- 8:f7063e4ba2c2
- Parent:
- 7:8f64ad5334ca
SSD447 - HW 1.1
Who changed what in which revision?
User | Revision | Line number | New 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 |
sbart | 8:f7063e4ba2c2 | 15 | #define PROGNAME "kl46z_btn_slider_toSerial_noDecimal\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); |
sbart | 8:f7063e4ba2c2 | 47 | |
sbart | 8:f7063e4ba2c2 | 48 | slcd.DP(0, false); //Disables the decimal point in position 0 |
scohennm | 6:a109f45fae66 | 49 | } |
scohennm | 6:a109f45fae66 | 50 | |
scohennm | 1:2688f68df85d | 51 | // -------------------------------- |
scohennm | 3:7e9670be412e | 52 | int main() { |
sim1sgl | 7:8f64ad5334ca | 53 | float sliderValue = 0.0; |
scohennm | 2:b49e5adf84df | 54 | |
sim1sgl | 7:8f64ad5334ca | 55 | pc.printf(PROGNAME); |
scohennm | 6:a109f45fae66 | 56 | dataTimer.start(); |
sbart | 8:f7063e4ba2c2 | 57 | dataTimer.reset(); |
scohennm | 6:a109f45fae66 | 58 | sprintf (lcdData,"%4.3f",0.0); |
scohennm | 6:a109f45fae66 | 59 | LCDMessNoDwell(lcdData); |
scohennm | 6:a109f45fae66 | 60 | |
scohennm | 6:a109f45fae66 | 61 | // Interrupt routine setups |
scohennm | 6:a109f45fae66 | 62 | rtButton.fall(&rtButtonPressed); |
scohennm | 6:a109f45fae66 | 63 | lfButton.fall(&lfButtonPressed); |
scohennm | 6:a109f45fae66 | 64 | |
scohennm | 3:7e9670be412e | 65 | // End of setup |
scohennm | 3:7e9670be412e | 66 | |
scohennm | 0:e23fffd4b9a7 | 67 | while(true) { |
sim1sgl | 7:8f64ad5334ca | 68 | // All the interrupts |
scohennm | 6:a109f45fae66 | 69 | |
scohennm | 6:a109f45fae66 | 70 | if (dataTimer.read_ms() > DATATIME){ |
sim1sgl | 7:8f64ad5334ca | 71 | // Read the slider value |
sim1sgl | 7:8f64ad5334ca | 72 | float newSliderValue = tsiScaling.readPercentage(); |
sim1sgl | 7:8f64ad5334ca | 73 | // Only do stuff with it if it's a new value or if it's not zero |
sim1sgl | 7:8f64ad5334ca | 74 | if(newSliderValue > 0.0 && newSliderValue != sliderValue) { |
sim1sgl | 7:8f64ad5334ca | 75 | sliderValue = newSliderValue; |
sbart | 8:f7063e4ba2c2 | 76 | |
sim1sgl | 7:8f64ad5334ca | 77 | sprintf (lcdData,"%4.3f", sliderValue); // Just to make things user readable |
sim1sgl | 7:8f64ad5334ca | 78 | |
scohennm | 6:a109f45fae66 | 79 | LCDMessNoDwell(lcdData); |
sim1sgl | 7:8f64ad5334ca | 80 | pc.printf("slider: %4.3f\r\n", sliderValue); |
scohennm | 6:a109f45fae66 | 81 | } |
scohennm | 6:a109f45fae66 | 82 | dataTimer.reset(); |
scohennm | 6:a109f45fae66 | 83 | } |
scohennm | 6:a109f45fae66 | 84 | |
scohennm | 0:e23fffd4b9a7 | 85 | } |
scohennm | 0:e23fffd4b9a7 | 86 | } |