This project is about creating an airplane instrument (such as an altimeter) for a flight simulator running on a PC. The code will read in two space-separated \"words\" containing the altitude and airspeed, with units, from a \"USBSerial port\". See my notebook page for details.

Dependencies:   TextLCD

Committer:
mblokzijl
Date:
Sat Nov 26 14:12:16 2011 +0000
Revision:
1:c97e837e48a6
Parent:
0:a2ecd3b777ac
publish2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mblokzijl 0:a2ecd3b777ac 1 #include "mbed.h"
mblokzijl 0:a2ecd3b777ac 2 #include "USBSerial.h"
mblokzijl 0:a2ecd3b777ac 3 #include "TextLCD.h"
mblokzijl 0:a2ecd3b777ac 4
mblokzijl 0:a2ecd3b777ac 5 //an LED to display activity
mblokzijl 0:a2ecd3b777ac 6 DigitalOut serial_activity_led(LED2);
mblokzijl 0:a2ecd3b777ac 7 //Virtual serial port over USB
mblokzijl 0:a2ecd3b777ac 8 USBSerial serial;
mblokzijl 0:a2ecd3b777ac 9 //The TextLCD
mblokzijl 0:a2ecd3b777ac 10 TextLCD lcd(p21, p22, p17, p18, p19, p20); // rs, e, d4-d7
mblokzijl 0:a2ecd3b777ac 11
mblokzijl 0:a2ecd3b777ac 12 int main() {
mblokzijl 0:a2ecd3b777ac 13 //initialise the LCD
mblokzijl 0:a2ecd3b777ac 14 lcd.printf("FlightSimInstru\nready!");
mblokzijl 0:a2ecd3b777ac 15
mblokzijl 1:c97e837e48a6 16 //setup some buffers - could use ints, too, but this way we can let the PC decide on the units, use floats etc.
mblokzijl 0:a2ecd3b777ac 17 uint8_t ias[128];
mblokzijl 0:a2ecd3b777ac 18 uint8_t alt[128];
mblokzijl 0:a2ecd3b777ac 19 //clear them
mblokzijl 0:a2ecd3b777ac 20 memset(ias,0,sizeof(ias)*sizeof(*ias));
mblokzijl 0:a2ecd3b777ac 21 memset(alt,0,sizeof(alt)*sizeof(*alt));
mblokzijl 0:a2ecd3b777ac 22
mblokzijl 0:a2ecd3b777ac 23 //toggle an LED to show us, that the mbed is alive.
mblokzijl 0:a2ecd3b777ac 24 while(1) {
mblokzijl 0:a2ecd3b777ac 25 //read two space separated strings
mblokzijl 0:a2ecd3b777ac 26 serial.scanf("%s %s", ias, alt);
mblokzijl 0:a2ecd3b777ac 27 //write them on the LCD
mblokzijl 0:a2ecd3b777ac 28 lcd.cls();
mblokzijl 0:a2ecd3b777ac 29 lcd.printf("Speed: %s\nAlt: %s", ias, alt);
mblokzijl 0:a2ecd3b777ac 30 //toggle activity LED
mblokzijl 0:a2ecd3b777ac 31 serial_activity_led = !serial_activity_led;
mblokzijl 0:a2ecd3b777ac 32 }
mblokzijl 0:a2ecd3b777ac 33 }