A little controller that links to a radio to send commands to sailboat.

Dependencies:   SLCD- mbed tsi_sensor

Committer:
bclaus
Date:
Wed Nov 19 18:20:28 2014 +0000
Revision:
0:dcad18121333
Initial;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bclaus 0:dcad18121333 1 #include "mbed.h"
bclaus 0:dcad18121333 2 #include "tsi_sensor.h"
bclaus 0:dcad18121333 3 #include "SLCD.h"
bclaus 0:dcad18121333 4
bclaus 0:dcad18121333 5 /* This defines will be replaced by PinNames soon */
bclaus 0:dcad18121333 6 #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
bclaus 0:dcad18121333 7 #define ELEC0 9
bclaus 0:dcad18121333 8 #define ELEC1 10
bclaus 0:dcad18121333 9 #elif defined (TARGET_KL05Z)
bclaus 0:dcad18121333 10 #define ELEC0 9
bclaus 0:dcad18121333 11 #define ELEC1 8
bclaus 0:dcad18121333 12 #else
bclaus 0:dcad18121333 13 #error TARGET NOT DEFINED
bclaus 0:dcad18121333 14 #endif
bclaus 0:dcad18121333 15
bclaus 0:dcad18121333 16 DigitalIn s1(PTC3);
bclaus 0:dcad18121333 17 DigitalIn s3(PTC12);
bclaus 0:dcad18121333 18
bclaus 0:dcad18121333 19 Serial radio(PTE0, PTE1);
bclaus 0:dcad18121333 20
bclaus 0:dcad18121333 21 SLCD slcd;
bclaus 0:dcad18121333 22
bclaus 0:dcad18121333 23 int main(void) {
bclaus 0:dcad18121333 24 PwmOut led(LED_GREEN);
bclaus 0:dcad18121333 25 TSIAnalogSlider tsi(ELEC0, ELEC1, 40);
bclaus 0:dcad18121333 26 radio.baud(9600);
bclaus 0:dcad18121333 27 float controlSail=0;
bclaus 0:dcad18121333 28 float controlRudder=0;
bclaus 0:dcad18121333 29
bclaus 0:dcad18121333 30 while (true) {
bclaus 0:dcad18121333 31 if(!s1){
bclaus 0:dcad18121333 32 slcd.clear(); // All segments off
bclaus 0:dcad18121333 33 slcd.Home(); // sets next charater to posistion 0 (start)
bclaus 0:dcad18121333 34 controlSail=tsi.readPercentage();
bclaus 0:dcad18121333 35 led = 1.0 - controlSail;
bclaus 0:dcad18121333 36 slcd.printf("S%2.2f",controlSail); // standard printf function, only charaters in ASCII_TO_WF_CODIFICATION_TABLE will display
bclaus 0:dcad18121333 37 radio.putc('s');
bclaus 0:dcad18121333 38 radio.putc((char)(controlSail*255));
bclaus 0:dcad18121333 39 }
bclaus 0:dcad18121333 40 else if(!s3){
bclaus 0:dcad18121333 41 slcd.clear(); // All segments off
bclaus 0:dcad18121333 42 slcd.Home(); // sets next charater to posistion 0 (start)
bclaus 0:dcad18121333 43 controlRudder=tsi.readPercentage();
bclaus 0:dcad18121333 44 led = 1.0 - controlRudder;
bclaus 0:dcad18121333 45 slcd.printf("R%2.2f",controlRudder); // standard printf function, only charaters in ASCII_TO_WF_CODIFICATION_TABLE will display
bclaus 0:dcad18121333 46 radio.putc('r');
bclaus 0:dcad18121333 47 radio.putc((char)(controlRudder*255));
bclaus 0:dcad18121333 48
bclaus 0:dcad18121333 49 }
bclaus 0:dcad18121333 50 else{
bclaus 0:dcad18121333 51 slcd.clear(); // All segments off
bclaus 0:dcad18121333 52 slcd.Home(); // sets next charater to posistion 0 (start)
bclaus 0:dcad18121333 53 slcd.putc('R'); // standard printf function, only charaters in ASCII_TO_WF_CODIFICATION_TABLE will display
bclaus 0:dcad18121333 54 slcd.CharPosition=3; // x=0 to 3, 0 is start position
bclaus 0:dcad18121333 55 slcd.putc('S'); // standard printf function, only charaters in ASCII_TO_WF_CODIFICATION_TABLE will display
bclaus 0:dcad18121333 56
bclaus 0:dcad18121333 57 }
bclaus 0:dcad18121333 58 wait(0.1);
bclaus 0:dcad18121333 59 }
bclaus 0:dcad18121333 60 }