Simple training demonstration to show the use of union and structure

Dependencies:   USBDevice mbed

Fork of OddExample1 by Jon Fuge

Committer:
jf1452
Date:
Tue Nov 26 11:39:57 2013 +0000
Revision:
6:5f4be4b8db14
Parent:
5:eb5c6ae5938b
Child:
7:4753526f342a
Structure Example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jf1452 1:d9da28105bef 1 /*******************************************************************************
jf1452 6:5f4be4b8db14 2 * This program demonstrates the use of structures *
jf1452 1:d9da28105bef 3 * *
jf1452 1:d9da28105bef 4 * Jon Fuge *
jf1452 2:db81cad8cb64 5 * V1.0 25/11/2013 First issue of code *
jf1452 1:d9da28105bef 6 *******************************************************************************/
dan 0:7dec7e9ac085 7
jf1452 2:db81cad8cb64 8 #include "mbed.h"
jf1452 2:db81cad8cb64 9 #include "USBSerial.h"
jf1452 3:0f80147842c2 10
jf1452 3:0f80147842c2 11 USBSerial serial; // Virtual serial port over USB. Use Teraterm as the interface
dan 0:7dec7e9ac085 12
jf1452 6:5f4be4b8db14 13 struct coordXY { int iX; int iY; }; // Define a new structure
jf1452 6:5f4be4b8db14 14
dan 0:7dec7e9ac085 15 int main() {
jf1452 6:5f4be4b8db14 16 coordXY Position1, Position2; // Declare variables with the new structure
jf1452 5:eb5c6ae5938b 17
jf1452 6:5f4be4b8db14 18 wait (10); // Wait 10 seconds to connect port
jf1452 3:0f80147842c2 19
jf1452 6:5f4be4b8db14 20 Position1.iX = 1; // Sets Position1.iX only
jf1452 6:5f4be4b8db14 21 Position1.iY = 2; // Sets Position1.iY only
jf1452 6:5f4be4b8db14 22 Position2.iX = 9; // Sets Position2.iX only
jf1452 6:5f4be4b8db14 23 Position2.iY = 6; // Sets Position2.iY only
jf1452 3:0f80147842c2 24
jf1452 6:5f4be4b8db14 25 serial.printf("Position1.iX:%i, Position1.iY:%i\n\r", Position1.iX, Position1.iY);
jf1452 6:5f4be4b8db14 26
jf1452 6:5f4be4b8db14 27 Position1 = Position2; // Directly load Position1 from Position2
jf1452 6:5f4be4b8db14 28 serial.printf("Position1.iX:%i, Position1.iY:%i\n\r", Position1.iX, Position1.iY);
jf1452 6:5f4be4b8db14 29
jf1452 6:5f4be4b8db14 30 for(;;) {} // Loop forever
jf1452 3:0f80147842c2 31 }