ODE_FUCKFISH
/
LabTest_No2
Sent data number exam2
main.cpp
- Committer:
- NorNick
- Date:
- 2015-11-17
- Revision:
- 1:b0441a01ac0d
- Parent:
- 0:7e5f31b719cf
File content as of revision 1:b0441a01ac0d:
#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(){ uint8_t value[100]; int index=0; uint8_t ch; pc.printf("Hello Nucleo !\n"); while(1){ index = 0; do { if (pc.readable()) // if there is an character to read from the device { ch = pc.getc(); // read it //if (index<100) // just to avoid buffer overflow // value[index++]=ch; // put it into the value array and increment the index } } while(index <= 99 && ch!='z' ); // loop until the '\n' character ch = '\0'; value[index]='\x0'; // add un 0 to end the c string //pc.printf("%s.\n",value); } } /* #include "mbed.h" //Serial micro(p9, p10); Serial pc(USBTX,USBRX); int err; char command[100]; int main() { /*micro.format(8, Serial::None, 1); micro.baud(19200); pc.format(8, Serial::None, 1); pc.baud(9600);*/ /* pc.printf("Hello Nucleo !\n"); while(1){ while (true) { if (pc.readable()) { pc.scanf("%s",command); break; } } pc.printf("Resulit: %s\n",command); pc.printf("Command Received: \r\n"); for (int i=0;i<sizeof(command);i++){ pc.printf("%X",command[i]); } pc.printf("\r\n"); pc.printf("Scanf returns: %d\r\n",err); } } */ /* #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"); } } } */