![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
02/07/15
Dependencies: mbed
main.cpp@70:168d67695a65, 2015-09-03 (annotated)
- Committer:
- aidanPJG
- Date:
- Thu Sep 03 15:10:51 2015 +0000
- Revision:
- 70:168d67695a65
- Parent:
- 69:74bffa1d3f7f
- Child:
- 71:60f06e7e50a3
commented and working with GUI];
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ADAMSTRUTT | 17:d9fb4a3780c7 | 1 | #include "mbed.h" |
ADAMSTRUTT | 17:d9fb4a3780c7 | 2 | #include "Calculate.h" |
ADAMSTRUTT | 35:085a674c9fdf | 3 | #include "Data.h" |
aidanPJG | 48:e9578f56534a | 4 | #include "UserInput.h" |
aidanPJG | 56:bf08d9e50ccc | 5 | #include "AddDetails.h" |
ADAMSTRUTT | 35:085a674c9fdf | 6 | |
aidanPJG | 70:168d67695a65 | 7 | Serial pc(USBTX, USBRX); // tx, rx comms for the pc to talk to the mbed |
aidanPJG | 70:168d67695a65 | 8 | DigitalOut led1(LED1); //led on the mbed, used for debugging |
aidanPJG | 70:168d67695a65 | 9 | DigitalOut led2(LED2); //" |
aidanPJG | 70:168d67695a65 | 10 | |
aidanPJG | 65:08b3eb9b95dd | 11 | string handshake(); |
aidanPJG | 59:2cbbd6fea55b | 12 | void run(); |
aidanPJG | 68:c6399471ea49 | 13 | int listen(); |
ADAMSTRUTT | 17:d9fb4a3780c7 | 14 | |
aidanPJG | 70:168d67695a65 | 15 | int main(void) //the first method that is run |
aidanPJG | 7:d6f78ba7c5f7 | 16 | { |
aidanPJG | 68:c6399471ea49 | 17 | |
aidanPJG | 70:168d67695a65 | 18 | if (handshake() == "success") //if the handshake returns success message |
aidanPJG | 65:08b3eb9b95dd | 19 | { |
aidanPJG | 70:168d67695a65 | 20 | run(); //then we run the program |
aidanPJG | 65:08b3eb9b95dd | 21 | } |
aidanPJG | 65:08b3eb9b95dd | 22 | led2= 1; |
aidanPJG | 59:2cbbd6fea55b | 23 | } |
aidanPJG | 68:c6399471ea49 | 24 | |
aidanPJG | 70:168d67695a65 | 25 | string handshake() //to test that the pc and mbed have comms |
aidanPJG | 70:168d67695a65 | 26 | { |
aidanPJG | 70:168d67695a65 | 27 | unsigned char input; //what the pc sends |
aidanPJG | 70:168d67695a65 | 28 | pc.printf("a\n"); //send the pc an 'a' |
aidanPJG | 59:2cbbd6fea55b | 29 | |
aidanPJG | 70:168d67695a65 | 30 | while(true) //keep doing this |
aidanPJG | 59:2cbbd6fea55b | 31 | { |
aidanPJG | 70:168d67695a65 | 32 | input = pc.getc(); //what the pc sends |
aidanPJG | 70:168d67695a65 | 33 | if (input == 'a') //did the pc send an 'a' as well? |
aidanPJG | 59:2cbbd6fea55b | 34 | { |
aidanPJG | 70:168d67695a65 | 35 | led1 = 1; //turn led on |
aidanPJG | 70:168d67695a65 | 36 | return "success" ; //return "success" |
aidanPJG | 59:2cbbd6fea55b | 37 | } |
aidanPJG | 59:2cbbd6fea55b | 38 | } |
aidanPJG | 59:2cbbd6fea55b | 39 | } |
aidanPJG | 70:168d67695a65 | 40 | void run() |
aidanPJG | 59:2cbbd6fea55b | 41 | { |
aidanPJG | 55:58e9836f5ad1 | 42 | int pins = inputNoOfPins(); //gets number of pins |
aidanPJG | 55:58e9836f5ad1 | 43 | double distance = inputDistance(); //gets the distance between the pins |
aidanPJG | 70:168d67695a65 | 44 | calculate(distance,pins); //runs calculate method. |
aidanPJG | 59:2cbbd6fea55b | 45 | } |