Programa encargado de leer el slider (sensor capacitivo entre SW1 y SW2) y alimentar con dicho valor el led verde con pwm. Además, muestra el dato por la pantalla de 4 segmentos integrada.

Dependencies:   mbed tsi_sensor SLCD

Committer:
marcospostemsky
Date:
Mon Oct 14 03:17:54 2019 +0000
Revision:
0:ff4e7f80c9fa
code finished

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcospostemsky 0:ff4e7f80c9fa 1 #include "mbed.h"
marcospostemsky 0:ff4e7f80c9fa 2 #include "tsi_sensor.h"
marcospostemsky 0:ff4e7f80c9fa 3 #include "SLCD.h"
marcospostemsky 0:ff4e7f80c9fa 4
marcospostemsky 0:ff4e7f80c9fa 5
marcospostemsky 0:ff4e7f80c9fa 6 /* This defines will be replaced by PinNames soon */
marcospostemsky 0:ff4e7f80c9fa 7 #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
marcospostemsky 0:ff4e7f80c9fa 8 #define ELEC0 9
marcospostemsky 0:ff4e7f80c9fa 9 #define ELEC1 10
marcospostemsky 0:ff4e7f80c9fa 10 #elif defined (TARGET_KL05Z)
marcospostemsky 0:ff4e7f80c9fa 11 #define ELEC0 9
marcospostemsky 0:ff4e7f80c9fa 12 #define ELEC1 8
marcospostemsky 0:ff4e7f80c9fa 13 #else
marcospostemsky 0:ff4e7f80c9fa 14 #error TARGET NOT DEFINED
marcospostemsky 0:ff4e7f80c9fa 15 #endif
marcospostemsky 0:ff4e7f80c9fa 16
marcospostemsky 0:ff4e7f80c9fa 17 SLCD slcd;
marcospostemsky 0:ff4e7f80c9fa 18
marcospostemsky 0:ff4e7f80c9fa 19 int main(void) {
marcospostemsky 0:ff4e7f80c9fa 20 PwmOut led(LED_GREEN);
marcospostemsky 0:ff4e7f80c9fa 21 TSIAnalogSlider tsi(ELEC0, ELEC1, 40);
marcospostemsky 0:ff4e7f80c9fa 22 float lectura = 0;
marcospostemsky 0:ff4e7f80c9fa 23 slcd.clear();
marcospostemsky 0:ff4e7f80c9fa 24
marcospostemsky 0:ff4e7f80c9fa 25
marcospostemsky 0:ff4e7f80c9fa 26 while (true) {
marcospostemsky 0:ff4e7f80c9fa 27 led = 1.0 - tsi.readPercentage();
marcospostemsky 0:ff4e7f80c9fa 28 lectura = tsi.readPercentage() * 1024;
marcospostemsky 0:ff4e7f80c9fa 29 slcd.CharPosition=0;
marcospostemsky 0:ff4e7f80c9fa 30 slcd.printf("%d",int(lectura)); // print the heading (NED compass) to the LCD
marcospostemsky 0:ff4e7f80c9fa 31 wait(0.2);
marcospostemsky 0:ff4e7f80c9fa 32 }
marcospostemsky 0:ff4e7f80c9fa 33 }