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.
Diff: main.cpp
- Revision:
- 0:f8c34fd5e223
- Child:
- 1:da6118c4da1f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Apr 19 10:00:38 2016 +0000
@@ -0,0 +1,29 @@
+#include "mbed.h"
+
+AnalogIn ain(A0);
+DigitalOut led1(LED_RED);
+DigitalOut led2(LED_GREEN);
+DigitalOut led3(LED_BLUE);
+DigitalOut led4(LED_USER);
+
+int main() {
+ float tmp1 = 0;
+ float tmp2 = 0;
+ float data;
+
+ printf("Sensor start!\n");
+ while(1) {
+ tmp1 = ain;
+ tmp2 = ain;
+ data = (tmp1 + tmp2) / 2.0f;
+
+ data = ain.read();
+ if ((0.121 <= data) && (data <= 0.970)) {
+ float range = 26.663 * pow((data * 3.3),-1.25);
+ printf("Distance : %4.2f[cm]\n",range) ;
+ } else {
+ printf("Distance : -----[cm]\n");
+ }
+ wait(0.5);
+ }
+}