a simple library to control an animatronic head
Alex.cpp
- Committer:
- mxjac
- Date:
- 2010-12-15
- Revision:
- 2:3920d79c79b1
- Parent:
- 1:c5edd3b18b79
- Child:
- 3:5271cc1a527b
File content as of revision 2:3920d79c79b1:
#include "Alex.h" Alex::Alex(SRF05 s, Servo e, Servo m, Servo l, Servo r):S(s), E(e), M(m), L(l), R(r), Led(LED1), pc(USBTX, USBRX) { } Alex::~Alex() { } void Alex::TestHead() { Led=1; wait(0.02); Led=0; } int Alex::Testpresence() { if((S.read()==0)||(S.read()>=500)){return 0;}//if presence is too close, return 0 if(S.read()>=40){return 1;}//if presence is too far, return 1 if((S.read()>=0)&&(S.read()<=40)){return 2;}//if presence is between O and 40cm, return 2 return 0; } void Alex::Move_eyes(int valuee) { for(int i=0; i<valuee; i++) { E=i; wait(0.1); } } void Alex::Move_mouth(int valuem) { for(int i=0; i<valuem; i++) { M=i; wait(0.1); } } void Alex::Move_leaning(int valuel) { for(int i=0; i<valuel; i++) { L=i; wait(0.1); } } void Alex::Move_rotation(int valuer) { for(int i=0; i<valuer; i++) { R=i; wait(0.1); } } void Alex::Simulate_Talking(int length) { for(int i=0; i<length; i++) { Move_mouth(100); wait(0.01); } } void Alex::Presence_too_far() { pc.printf("You are too far, I can't see you !"); Simulate_Talking(4); wait(3); pc.printf("Is there somebody ?"); Simulate_Talking(4); wait(3); } void Alex::displaydistance() { pc.printf("Distance : %4i\r\n", S.read()); }