lab4
Dependencies: mbed
Fork of lab4fra221 by
Revision 0:bc396bb049ae, committed 2017-11-24
- Comitter:
- csggreen
- Date:
- Fri Nov 24 04:10:00 2017 +0000
- Commit message:
- lab3
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r bc396bb049ae main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Nov 24 04:10:00 2017 +0000 @@ -0,0 +1,229 @@ +#include "mbed.h" +Serial pc(D8, D2); + +DigitalOut gsled1(D3); +DigitalOut gsled2(D4); +DigitalOut gsled3(D5); +DigitalOut gsled4(D6); + +AnalogIn analog_value(A1);//อานค่าAnalogจากขาA1 +uint8_t state_show=0; +uint8_t data; +uint8_t Bluet; +float formvolume;//รับค่าจากR +float mVolt;//รับค่าที่แปลงแล้วหน่วยmV +float Volt; +int x=0; + +void Number0(){//float Number + gsled1 = 0; + gsled2 = 0; + gsled3 = 0; + gsled4 = 0; + } +void Number1(){// Number + gsled1 = 0; + gsled2 = 0; + gsled3 = 0; + gsled4 = 1; + } +void Number2(){ + gsled1 = 0; + gsled2 = 0; + gsled3 = 1; + gsled4 = 0; + } +void Number3(){ + gsled1 = 0; + gsled2 = 0; + gsled3 = 1; + gsled4 = 1; + } +void Number4(){ + gsled1 = 0; + gsled2 = 1; + gsled3 = 0; + gsled4 = 0; + } +void Number5(){ + gsled1 = 0; + gsled2 = 1; + gsled3 = 0; + gsled4 = 1; + } +void Number6(){ + gsled1 = 0; + gsled2 = 1; + gsled3 = 1; + gsled4 = 0; + } +void Number7(){ + gsled1 = 0; + gsled2 = 1; + gsled3 = 1; + gsled4 = 1; + } +void Number8(){ + gsled1 = 1; + gsled2 = 0; + gsled3 = 0; + gsled4 = 0; + } +void Number9(){ + gsled1 = 1; + gsled2 = 0; + gsled3 = 0; + gsled4 = 1; + } +void segmentfunction(){ + if (Bluet==0){ + Number0(); + } + else if (Bluet==1){ + Number1(); + } + else if (Bluet==2){ + Number2(); + } + else if (Bluet==3){ + Number3(); + } + else if (Bluet==4){ + Number4(); + } + else if (Bluet==5){ + Number5(); + } + else if (Bluet==6){ + Number6(); + } + else if (Bluet==7){ + Number7(); + } + else if (Bluet==8){ + Number8(); + } + else if (Bluet==9){ + Number9(); + } +} +void showmenu(){ + pc.printf("************\n"); + pc.printf(" MENU \n"); + pc.printf("************\n"); + pc.printf("1.PLAY SEGMENT \n"); + pc.printf("2.READ VR\n"); + state_show =1; + } +int main() +{ + + while(1) { + + if (state_show == 0){ + showmenu(); + pc.readable(); + data = pc.getc(); + x=0; + if (data=='1'){ + pc.printf("PLAY SEGMENT \n"); + pc.readable(); + data = pc.getc(); + while(x==0){ + while (data=='0'){ + pc.printf("-->0<-- \n\n"); + Bluet=0; + segmentfunction(); + data = pc.getc(); + } + while (data=='1'){ + pc.printf("-->1<-- \n\n"); + Bluet=1; + segmentfunction(); + data = pc.getc(); + } + while (data=='2'){ + pc.printf("-->2<-- \n\n"); + Bluet=2; + segmentfunction(); + data = pc.getc(); + } + while (data=='3'){ + pc.printf("-->3<-- \n\n"); + Bluet=3; + segmentfunction(); + data = pc.getc(); + } + while (data=='4'){ + pc.printf("-->4<-- \n\n"); + Bluet=4; + segmentfunction(); + data = pc.getc(); + } + while (data=='5'){ + pc.printf("-->5<-- \n\n"); + Bluet=5; + segmentfunction(); + data = pc.getc(); + } + while (data=='6'){ + pc.printf("-->6<-- \n\n"); + Bluet=6; + segmentfunction(); + data = pc.getc(); + } + while (data=='7'){ + pc.printf("-->7<-- \n\n"); + Bluet=7; + segmentfunction(); + data = pc.getc(); + } + while (data=='8'){ + pc.printf("-->8<-- \n\n"); + Bluet=8; + segmentfunction(); + data = pc.getc(); + } + while (data=='9'){ + pc.printf("-->9<-- \n\n"); + Bluet=9; + segmentfunction(); + data = pc.getc(); + } + while (data=='x'){ + x=1; + state_show = 0; + break; + } + + } + } + + if (data=='2'){ + while(x==0){ + while(data=='2'){ + formvolume = analog_value.read(); + mVolt = formvolume * 5000; + Volt = mVolt/1000; + pc.printf("VRvalue %0.2f V\n",Volt); + wait(0.2); + if(pc.readable()){ + data = pc.getc(); + if(data == 'x'){ + x=1; + state_show = 0; + break; + } + } + } + + } + + + } + } + } + + + +} \ No newline at end of file
diff -r 000000000000 -r bc396bb049ae mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Nov 24 04:10:00 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/fb8e0ae1cceb \ No newline at end of file