a simple library to control an animatronic head

Alex.cpp

Committer:
mxjac
Date:
2010-12-12
Revision:
0:8474cbec06bd
Child:
1:c5edd3b18b79

File content as of revision 0:8474cbec06bd:

#include "Alex.h"
Serial pc(USBTX, USBRX); // tx, rx => serialize mBed with the pc
PwmOut Led(LED1);

Alex::Alex(SRF05 s, Servo e, Servo m, Servo l, Servo r):S(s), E(e), M(m), L(l), R(r)
{
}
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);
    }
}