ODE_FUCKFISH
/
LabTest_No2
Sent data number exam2
Diff: main.cpp
- Revision:
- 0:7e5f31b719cf
- Child:
- 1:b0441a01ac0d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Oct 28 15:16:55 2015 +0000 @@ -0,0 +1,166 @@ +#include "mbed.h" +//#include "stdlib.h" +/* +//------------------------------------ +// Hyperterminal configuration +// 9600 bauds, 8-bit data, no parity +//------------------------------------ + +Serial pc(SERIAL_TX, SERIAL_RX); + +//Serial pc(D8, D2); + +AnalogIn analog_value(A1); + +DigitalIn Sw(D3); + +BusOut ledSet1(D11, D10, D9, D4); //อย่าลืมกลับเลขด้วยเพราะมันต้องใช้ 7-Segment +BusOut ledSet2(D15, D14, D13, D12); //อย่าลืมกลับเลขด้วยเพราะมันต้องใช้ 7-Se + +int main() +{ + int i; + int t; + uint8_t data; + char rt[2]; + int Number[2]={0}; + + + ledSet1 = ledSet2 = 0; + pc.printf("Hello Nucleo !\n"); + while(1) { + + pc.gets(rt,3); + pc.printf(" %s \r\n",rt); + //pc.printf(" %d is desub.\n",atoi(rt)/10); + //pc.printf(" %d is Conveart.\n",atoi(rt)%10); + ledSet1 = atoi(rt)/10; + ledSet2 = atoi(rt)%10; + } + } +*/ + +#include "mbed.h" + +//------------------------------------ +// Hyperterminal configuration +// 9600 bauds, 8-bit data, no parity +//------------------------------------ + +Serial pc(SERIAL_TX, SERIAL_RX); + +//Serial device(D8, D2); + +AnalogIn analog_value(A1); + +DigitalIn Sw(D3); + +BusOut ledSet1(D11, D10, D9, D4); //อย่าลืมกลับเลขด้วยเพราะมันต้องใช้ 7-Segment +BusOut ledSet2(D15, D14, D13, D12); //อย่าลืมกลับเลขด้วยเพราะมันต้องใช้ 7-Se + +int main(){ + char value[100]; + int index=0; + char ch; + pc.printf("Hello Nucleo !\n"); + while(1){ + index = 0; + do + { + if (pc.readable()) // if there is an character to read from the device + { + //wait(0.75); + ch = pc.getc(); // read it + pc.printf(" %c \n",ch); + if (index<100) // just to avoid buffer overflow + value[index++]=ch; // put it into the value array and increment the index + } + } while (ch!='?'); // loop until the '\n' character + value[index]='\x0'; // add un 0 to end the c string + pc.printf(" %s \n",value); + } +} + +/* +#include "mbed.h" +#include <string> + +//------------------------------------ +// Hyperterminal configuration +// 9600 bauds, 8-bit data, no parity +//------------------------------------ + +Serial pc(SERIAL_TX, SERIAL_RX); + +//Serial pc(D8, D2); + +AnalogIn analog_value(A1); + +DigitalIn Sw(D3); + +BusOut ledSet1(D11, D10, D9, D4); //อย่าลืมกลับเลขด้วยเพราะมันต้องใช้ 7-Segment +BusOut ledSet2(D15, D14, D13, D12); //อย่าลืมกลับเลขด้วยเพราะมันต้องใช้ 7-Segment + + + +int main() +{ + + uint8_t state_menu=0; + uint8_t data; + char value[2]; + int index=0; + + ledSet1 = ledSet2 = 0; + pc.printf("Hello Nucleo !\n"); + while(1) { + + if(state_menu == 0) { + pc.printf("Input Value Between 00-99 OR Select a To Read Analog Voltage. \n"); + state_menu = 1; + } + + index = 0; + do + { + if (pc.readable()) // if there is an character to read from the device + { + data = pc.getc(); // read it + if (index<2) // just to avoid buffer overflow + value[index++]=data; // put it into the value array and increment the index + } + } while (index <= 1 && data != 'a' ); // loop until the '\n' character + data = '\0'; + value[index]='\x0'; // add un 0 to end the c string + pc.printf("\n %d\t%s \n",--index,value); + + pc.printf("\n"); + state_menu=0; + if(value[0]!='a'){ + if(value[1]!='a'){ + pc.printf(" %s \r\n",value); + pc.printf(" %d is desub.\n",atoi(value)/10); + pc.printf(" %d is Conveart.\n",atoi(value)%10); + ledSet1 = atoi(value)/10; + ledSet2 = atoi(value)%10; + } + else{ + pc.printf("plz select Input No 00-99 or a\n"); + pc.printf("\n\n"); + } + } + else if(value[0] == 'a'){ + ledSet1 = ledSet2 = 0; + state_menu=0; + float value = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) + value = (value * 3300)/1000; // Change the value to be in the 0 to 3300 range + pc.printf("Status Voltage :: %.2f volte. \n",value); + } + else{ + pc.printf("plz select Input No 00-99 or a\n"); + pc.printf("\n\n"); + } + + } + } +*/ \ No newline at end of file