From: acevest Date: Tue, 2 Dec 2014 14:08:22 +0000 (+0800) Subject: add servo X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=702fec09f23e4dadbcaa4cbc240be49c7dbc77ea;p=acecode.git add servo --- diff --git a/arduino/Sensors/Sensors/Sensors.ino b/arduino/Sensors/Sensors.ino similarity index 64% rename from arduino/Sensors/Sensors/Sensors.ino rename to arduino/Sensors/Sensors.ino index 51e9800..24d66bd 100644 --- a/arduino/Sensors/Sensors/Sensors.ino +++ b/arduino/Sensors/Sensors.ino @@ -1,6 +1,13 @@ +#include + const int ledPin = 12; int cnt = 0; +Servo servo; + +int OldHumanBody = 0; + + void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); @@ -8,6 +15,8 @@ void setup() { pinMode(0, INPUT); pinMode(1, INPUT); pinMode(2, INPUT); + + servo.attach(9); } void loop() { @@ -17,7 +26,7 @@ void loop() { int tv = analogRead(1); // Temperature - int bd = analogRead(2); // Human Body + int hb = analogRead(2); // Human Body delay(100); @@ -33,14 +42,14 @@ void loop() { Serial.println(tv); Serial.print("Body: "); - Serial.println(bd); + Serial.println(hb); Serial.print(">"); Serial.print(lv); Serial.print(":"); Serial.print(temperature); Serial.print(":"); - Serial.print(bd); + Serial.print(hb); Serial.println(" "); } @@ -53,5 +62,24 @@ void loop() { digitalWrite(ledPin, LOW); } + int degree = map(hb, 0, 1023, 0, 179); + + /* + Serial.print("fffffffffffffffffffffffffffffffffff: "); + Serial.print(OldHumanBody); + Serial.print(" "); + Serial.print(hb); + Serial.println(" ");*/ + + if(OldHumanBody ==0 && hb == 0) + { + + } + else + { + servo.write(degree); + } + + OldHumanBody = hb; }