]> Zhao Yanbai Git Server - acecode.git/commitdiff
add arduino Ultrasonic Sensor Code
authorAceVest <zhaoyanbai@126.com>
Tue, 2 Sep 2014 14:33:07 +0000 (22:33 +0800)
committerAceVest <zhaoyanbai@126.com>
Tue, 2 Sep 2014 14:33:07 +0000 (22:33 +0800)
arduino/UltrasonicSensor/UltrasonicSensor.ino [new file with mode: 0644]
tools/htn.c [new file with mode: 0644]
tools/nth.cc [new file with mode: 0644]

diff --git a/arduino/UltrasonicSensor/UltrasonicSensor.ino b/arduino/UltrasonicSensor/UltrasonicSensor.ino
new file mode 100644 (file)
index 0000000..4462e41
--- /dev/null
@@ -0,0 +1,27 @@
+const int TrigPin = 2;  // 2
+const int EchoPin = 3;  // ~3
+
+float dist;
+
+void setup()
+{
+  Serial.begin(9600);
+  pinMode(TrigPin, OUTPUT);
+  pinMode(EchoPin, INPUT);
+  Serial.println("Ultrasonic Sensor:");
+}
+
+void loop()
+{
+  digitalWrite(TrigPin, LOW);
+  delayMicroseconds(2);
+  digitalWrite(TrigPin, HIGH);
+  delayMicroseconds(10);
+  digitalWrite(TrigPin, LOW);
+  
+  dist = pulseIn(EchoPin, HIGH) / 58.0;
+  
+  Serial.print(dist);
+  Serial.println("cm");
+  delay(100);
+}
diff --git a/tools/htn.c b/tools/htn.c
new file mode 100644 (file)
index 0000000..256f393
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * ------------------------------------------------------------------------
+ *   File Name: htn.c
+ *      Author: Zhao Yanbai
+ *              Sat Jul 12 17:00:31 2014
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+#include<stdio.h>
+
+int main(int argc, char *argv[]){
+       unsigned int ch;
+       while(scanf("%x",&ch) != EOF)
+               printf("%u\n",ch);
+
+       return 0;
+}
diff --git a/tools/nth.cc b/tools/nth.cc
new file mode 100644 (file)
index 0000000..aada7fc
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * ------------------------------------------------------------------------
+ *   File Name: nth.cc
+ *      Author: Zhao Yanbai
+ *              Sat Jul 12 16:20:37 2014
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+#include<iostream>
+#include<cstdio>
+using namespace std;
+
+int main(int argc, char *argv[]) {
+
+    unsigned int n;
+
+    while(cin >> n)
+    {
+        printf("%08x\n", n);
+    }
+
+       return 0;
+}