Using capacitive touch sensor to control servo speed. Using NMHU Shield.

Dependencies:   Servo mbed

Fork of servo_control_shield_v1 by Bresdin O'Malley

Committer:
bomalley
Date:
Thu Mar 12 19:29:10 2015 +0000
Revision:
1:9d15bcabb1f2
Parent:
0:6138ceae43f5
Using capacitive touch sensor to control servo speed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bomalley 0:6138ceae43f5 1 #include "mbed.h"
bomalley 0:6138ceae43f5 2 #include "Servo.h"
bomalley 1:9d15bcabb1f2 3 #include "TSISensor.h"
bomalley 0:6138ceae43f5 4
bomalley 0:6138ceae43f5 5 #define WAITTIME 0.2
bomalley 0:6138ceae43f5 6
bomalley 0:6138ceae43f5 7 /*
bomalley 0:6138ceae43f5 8 * Written by: Bresdin O'Malley 2015
bomalley 0:6138ceae43f5 9 * Servo control for shield NMHU (New Mexico Highlands University) KL-46Z.
bomalley 1:9d15bcabb1f2 10 * This will control two servos ~ Using capacitive touch sensor to control servo speed
bomalley 0:6138ceae43f5 11
bomalley 0:6138ceae43f5 12 */
bomalley 0:6138ceae43f5 13
bomalley 0:6138ceae43f5 14 Servo myservo1(PTC9);
bomalley 0:6138ceae43f5 15 Servo myservo2(PTC8);
bomalley 0:6138ceae43f5 16
bomalley 1:9d15bcabb1f2 17 TSISensor tsiScaling;
bomalley 1:9d15bcabb1f2 18 float tempValue;
bomalley 1:9d15bcabb1f2 19
bomalley 0:6138ceae43f5 20 int main() {
bomalley 1:9d15bcabb1f2 21 while(true) {
bomalley 1:9d15bcabb1f2 22
bomalley 1:9d15bcabb1f2 23 tempValue = tsiScaling.readPercentage();
bomalley 1:9d15bcabb1f2 24
bomalley 1:9d15bcabb1f2 25 if(tempValue > 0)
bomalley 1:9d15bcabb1f2 26 {
bomalley 1:9d15bcabb1f2 27 //change speed of servos
bomalley 1:9d15bcabb1f2 28 myservo1.write(tempValue);
bomalley 1:9d15bcabb1f2 29 myservo2.write(tempValue);
bomalley 0:6138ceae43f5 30 }
bomalley 1:9d15bcabb1f2 31 else
bomalley 1:9d15bcabb1f2 32 {
bomalley 1:9d15bcabb1f2 33 myservo1.write(0);
bomalley 1:9d15bcabb1f2 34 myservo2.write(0);
bomalley 1:9d15bcabb1f2 35 }
bomalley 1:9d15bcabb1f2 36 wait(WAITTIME);
bomalley 0:6138ceae43f5 37 }
bomalley 0:6138ceae43f5 38 }