lab4
Dependencies: mbed
Fork of FRA221_lab4 by
Diff: main.cpp
- Revision:
- 0:37c54bfab97b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Nov 23 14:51:29 2017 +0000 @@ -0,0 +1,154 @@ +#include "mbed.h" + +//------------------------------------ +// Hyperterminal configuration +// 9600 bauds, 8-bit data, no parity +//------------------------------------ + +Serial pc(D8,D2); +BusOut myleds(D3,D4,D5,D6); +AnalogIn analog_value(A1); + + +int main() +{ + + uint8_t state_menu=0; + uint8_t state_show=0; + uint8_t state_exit=0; + uint8_t data; + uint8_t num; + float analogread; + + + while(1) { + if(state_show == 0) { + pc.printf("************\n"); + pc.printf(" Menu \n"); + pc.printf("************\n"); + pc.printf("1.SHOW 7-SEGMENT \n"); + pc.printf("2.READ VR \n"); + state_show =1; + } + if(pc.readable()) { + data = pc.getc(); + pc.printf("\n"); + state_show =0; + state_exit =0; + + switch(data) { + case '1': + do { + if(state_menu == 0) { + pc.printf("SHOW 7-SEGMENT \n"); + pc.printf("a.TEST 7 SEGMENT \n"); + pc.printf("x.Exit\n"); + state_menu = 1; + } + + if(pc.readable()) { + data = pc.getc(); + pc.printf("\n"); + state_menu=0; + + switch(data) { + case 'a': + pc.printf("INSERT YOUR NUMBER(0-9) : "); + num = pc.getc(); + if(num==48){ + num=0; + } + if(num==49){ + num=1; + } + if(num==50){ + num=2; + } + if(num==51){ + num=3; + } + if(num==52){ + num=4; + } + if(num==53){ + num=5; + } + if(num==54){ + num=6; + } + if(num==55){ + num=7; + } + if(num==56){ + num=8; + } + if(num==57){ + num=9; + } + myleds = num; + pc.printf("NUM = "); + pc.printf("%d \n",num); + break; + + case 'x': + state_exit =1; + break; + + default: + pc.printf("plz select a or x\n"); + pc.printf("\n\n"); + break; + } + } + } while(state_exit ==0); + + pc.printf("\n"); + break; + + case '2': + + do { + if(state_menu == 0) { + pc.printf("Print Test\n"); + pc.printf("a.- Read VR -\n"); + pc.printf("x.Exit\n"); + state_menu = 1; + } + if(pc.readable()) { + data = pc.getc(); + pc.printf("\n"); + state_menu=0; + analogread = analog_value.read()* 3.30; // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range) + + switch(data) { + + case 'a': + pc.printf("VR : "); + pc.printf("%0.2f\n",analogread); + pc.printf(" volt"); + break; + + + case 'x': + state_exit =1; + break; + + default: + pc.printf("plz select a or s\n"); + pc.printf("\n"); + break; + } + } + } while(state_exit ==0); + pc.printf("\n"); + break; + + + default: + pc.printf("plz select 1 or 2 only\n"); + pc.printf("\n"); + break; + } + } + } +} \ No newline at end of file