Using capacitive touch sensor to control servo speed. Using NMHU Shield.
Fork of servo_control_shield_v1 by
Diff: main.cpp
- Revision:
- 1:9d15bcabb1f2
- Parent:
- 0:6138ceae43f5
diff -r 6138ceae43f5 -r 9d15bcabb1f2 main.cpp --- a/main.cpp Thu Mar 12 18:31:10 2015 +0000 +++ b/main.cpp Thu Mar 12 19:29:10 2015 +0000 @@ -1,24 +1,38 @@ #include "mbed.h" #include "Servo.h" +#include "TSISensor.h" #define WAITTIME 0.2 /* * Written by: Bresdin O'Malley 2015 * Servo control for shield NMHU (New Mexico Highlands University) KL-46Z. -* This will control two servos. +* This will control two servos ~ Using capacitive touch sensor to control servo speed */ Servo myservo1(PTC9); Servo myservo2(PTC8); +TSISensor tsiScaling; +float tempValue; + int main() { -while(true) { - for(float p=0; p<1.0; p += 0.1) { - myservo1.write(p); - myservo2.write(p); - wait(WAITTIME); +while(true) { + + tempValue = tsiScaling.readPercentage(); + + if(tempValue > 0) + { + //change speed of servos + myservo1.write(tempValue); + myservo2.write(tempValue); } + else + { + myservo1.write(0); + myservo2.write(0); + } + wait(WAITTIME); } } \ No newline at end of file