Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 0:266249de096d, committed 2017-11-23
- Comitter:
- wonner163
- Date:
- Thu Nov 23 14:48:53 2017 +0000
- Commit message:
- lab2-1
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 266249de096d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Nov 23 14:48:53 2017 +0000 @@ -0,0 +1,45 @@ +#include "mbed.h" + +AnalogIn analog_value(A1); // กำหนดขา A1 เป็นขาที่รับค่า analog และสร้างตัวแปร analog_value +BusOut led0(D2, D3, D4, D5,D6, D7, D8, D9);//ใช้ busout ประกาศขาที่เป็น digitaloutput โดยค่าที่ออกมาจะเป็นเลขฐาน 2 +Serial pc(D1, D0); + + +int main() { + double meas; + while(1) { + meas = analog_value.read(); // ใช้อ่านค่า analog_value มาเก็บในตัวแปรซึ่งค่าที่รับมาจะมีค่าอยู่ในช่วงระหว่าง 0.0-1.0 Volt + meas = meas * 3300; // Change the value to be in the 0 to 3300 range + pc.printf("%f",meas); + pc.printf("\n"); + if (meas < 10 ) + { + led0 = 0; //output = 0000 0000 + } + else if (meas > 10 && meas < 412.5 ) { // นำค่า 3300 มาหารด้วย 8 จะได้ค่า 412.5 + led0 = 1; //output = 0000 0001 + } + else if (meas >= 412.5 && meas < 825.0) { + led0 = 3;//output = 0000 0011 + } + else if (meas >= 825.0 && meas < 1237.5){ + led0 = 7;//output = 0000 0111 + } + else if (meas >= 1650.0 && meas < 2062.5){ + led0 = 15; //output = 0000 1111 + } + else if (meas >= 2062.5 && meas < 2475.0){ + led0 = 31;//output = 0001 1111 + } + else if (meas >=2475.0 && meas < 2887.5){ + led0 = 63;//output = 0011 1111 + } + else if (meas >= 2887.5 && meas < 3300.0){ + led0 = 127;//output = 0111 1111 + } + else if (meas >= 3300.0){ + led0 = 255;//output = 1111 1111 + } + wait(0.2); // 200 ms + } +} \ No newline at end of file
diff -r 000000000000 -r 266249de096d mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Nov 23 14:48:53 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b484a57bc302 \ No newline at end of file