Code to display sensor input of Axis y, If the user presses 'e' then exit the loop. Not working and can not figuer out why

Dependencies:   mbed

Committer:
Nightxp
Date:
Fri Apr 05 19:32:54 2013 +0000
Revision:
0:8bba0e955d47
Trying to find out how to skip getchar() when no input is entered

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nightxp 0:8bba0e955d47 1 #include "mbed.h"
Nightxp 0:8bba0e955d47 2 #include "stdio.h"
Nightxp 0:8bba0e955d47 3
Nightxp 0:8bba0e955d47 4 AnalogIn Ac1(p15); //Accelerometer #1 Y axis
Nightxp 0:8bba0e955d47 5
Nightxp 0:8bba0e955d47 6 float while1 = 0;
Nightxp 0:8bba0e955d47 7
Nightxp 0:8bba0e955d47 8 float maxTemp; //Maximum axis value
Nightxp 0:8bba0e955d47 9 float minTemp; //Minimum axis value
Nightxp 0:8bba0e955d47 10
Nightxp 0:8bba0e955d47 11 float yAxis;
Nightxp 0:8bba0e955d47 12 float zAxis;
Nightxp 0:8bba0e955d47 13
Nightxp 0:8bba0e955d47 14 char c;
Nightxp 0:8bba0e955d47 15
Nightxp 0:8bba0e955d47 16 int Menu = 1;
Nightxp 0:8bba0e955d47 17 int temp = 0;
Nightxp 0:8bba0e955d47 18
Nightxp 0:8bba0e955d47 19 while (temp == 1)
Nightxp 0:8bba0e955d47 20 {
Nightxp 0:8bba0e955d47 21 yAxis = Ac1; //yAxis = the analog input pin of AC1
Nightxp 0:8bba0e955d47 22
Nightxp 0:8bba0e955d47 23 if(yAxis > maxTemp) //Find the maximum value of yAxis
Nightxp 0:8bba0e955d47 24 maxTemp = yAxis;
Nightxp 0:8bba0e955d47 25
Nightxp 0:8bba0e955d47 26 if(minTemp == 0) //if yAsix is too low (i.e zero) then reset to the currnt value. (yaxis should never hit 0;)
Nightxp 0:8bba0e955d47 27 minTemp = yAxis;
Nightxp 0:8bba0e955d47 28
Nightxp 0:8bba0e955d47 29 if(yAxis < minTemp) //Find the minimum value of yAxis
Nightxp 0:8bba0e955d47 30 minTemp = yAxis;
Nightxp 0:8bba0e955d47 31
Nightxp 0:8bba0e955d47 32 printf("| %0.3f | %0.5f | %0.3f | %c \r", minTemp, yAxis, maxTemp, c);
Nightxp 0:8bba0e955d47 33
Nightxp 0:8bba0e955d47 34 c = getchar(); //Exit this loop if the user presses 'e'
Nightxp 0:8bba0e955d47 35 if(c == 'e')
Nightxp 0:8bba0e955d47 36 temp = 0;
Nightxp 0:8bba0e955d47 37 }