Teerapong Apiraungpituk
/
Nucleo_serial_menu_p
=3=
Fork of Nucleo_serial_menu by
main.cpp
- Committer:
- 57340500039
- Date:
- 2015-11-16
- Revision:
- 1:59178970c02b
- Parent:
- 0:f4e546303b4e
File content as of revision 1:59178970c02b:
#include "mbed.h" #include <string.h> DigitalOut led1(D11); DigitalOut led2(D3); DigitalOut led3(D4); DigitalOut led4(D5); DigitalOut led5(D6); DigitalOut led6(D7); DigitalOut led7(D9); DigitalOut led8(D10); DigitalOut led[8] = {led1,led2,led3,led4,led5,led6,led7,led8}; AnalogIn analog_value(A0); //------------------------------------ //------------------------------------ Serial pc(D8, D2); //D8 = Tx, D2 = Rx int funcA(){ uint8_t a=0; uint8_t b=0; char input[2]={0,0}; input[0] = pc.getc(); input[1] = pc.getc(); a = input[0]-'0'; b = input[1]-'0'; if(a>=9||a<0) a = 0; if(b>=9||b<0) b = 0; switch(a){ case 0: led5 = 0; led6 = 0; led7 = 0; led8 = 0; break; case 1: led5 = 1; led6 = 0; led7 = 0; led8 = 0; break; case 2: led5 = 0; led6 = 1; led7 = 0; led8 = 0; break; case 3: led5 = 1; led6 = 1; led7 = 0; led8 = 0; break; case 4: led5 = 0; led6 = 0; led7 = 1; led8 = 0; break; case 5: led5 = 1; led6 = 0; led7 = 1; led8 = 0; break; case 6: led5 = 0; led6 = 1; led7 = 1; led8 = 0; break; case 7: led5 = 1; led6 = 1; led7 = 1; led8 = 0; break; case 8: led5 = 0; led6 = 0; led7 = 0; led8 = 1; break; case 9: led5 = 1; led6 = 0; led7 = 0; led8 = 1; break; } switch(b){ case 0: led1 = 0; led2 = 0; led3 = 0; led4 = 0; break; case 1: led1 = 1; led2 = 0; led3 = 0; led4 = 0; break; case 2: led1 = 0; led2 = 1; led3 = 0; led4 = 0; break; case 3: led1 = 1; led2 = 1; led3 = 0; led4 = 0; break; case 4: led1 = 0; led2 = 0; led3 = 1; led4 = 0; break; case 5: led1 = 1; led2 = 0; led3 = 1; led4 = 0; break; case 6: led1 = 0; led2 = 1; led3 = 1; led4 = 0; break; case 7: led1 = 1; led2 = 1; led3 = 1; led4 = 0; break; case 8: led1 = 0; led2 = 0; led3 = 0; led4 = 1; break; case 9: led1 = 1; led2 = 0; led3 = 0; led4 = 1; break; } return 0; } int funcB(){ float meas; meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) meas = meas * 3.3; // Change the value to be in the 0 to 33 range pc.printf("%f\n",meas); return 0; } int main(){ char input = 'x'; while(1){ pc.printf("mode a : input 2 digits number.\r\n"); pc.printf("mode b : read analog from VR.\r\n\r\n"); pc.printf("input : "); input = pc.getc(); switch(input){ case 'a': pc.printf("mode a:\r\n");funcA();break; case 'b': pc.printf("mode b:\r\n");funcB();break; } pc.printf("\r\n**************************\r\n\r\n"); } }