Finch C API  1
Documentation for the Finch's C Library
Macros | Functions
Finch.h File Reference

Go to the source code of this file.

Macros

#define _LINUX_
 Sets the API for use with Mac or Linux, comment out if using Windows.
 
#define Sleep(mm)   usleep(mm*1000)
 If using Linux/Mac, redefines sleep to match that OS call.
 

Functions

int Fin_Init (void)
 Fin_init(void).
 
int Fin_Exit (void)
 Fin_Exit(void).
 
int Fin_Motor (int tenth, int left, int right)
 Fin_Motor(tenth, left, right).
 
int Fin_Move (int tenth, int left, int right)
 Fin_Move(tenth, left, right).
 
int Fin_Speed (int *left, int *right)
 Fin_Speed(*left, *right).
 
int Fin_LED (int red, int green, int blue)
 Fin_LED(red, green, blue).
 
int Fin_Buzzer (int msec, int freq)
 Fin_Buzzer(msec, freq).
 
int Fin_Lights (int *left, int *right)
 Fin_Lights(*left, *right).
 
int Fin_Obstacle (int *left, int *right)
 Fin_Obstacle(*left, *right).
 
int Fin_Temp (float *temp)
 Fin_Temp(*temp).
 
int Fin_Accel (float *x, float *y, float *z, int *tap, int *shake)
 Fin_Accel(*x, *y, *z, *tap, *shake).
 
int kbhit (void)
 

Macro Definition Documentation

#define _LINUX_

Sets the API for use with Mac or Linux, comment out if using Windows.

#define Sleep (   mm)    usleep(mm*1000)

If using Linux/Mac, redefines sleep to match that OS call.

Function Documentation

int Fin_Accel ( float *  x,
float *  y,
float *  z,
int *  tap,
int *  shake 
)

Fin_Accel(*x, *y, *z, *tap, *shake).

Get acceleration values and tap/shaken flags. Returned acceleration values are in 'g' (in 1/1000 units) and range from +1.5 to -1.5g.

Parameters
*xpointer for the x-axis acceleration
*zpointer for the y-axis acceleration
*ypointer for the z-axis acceleration
*tappointer to return the tap flag (0 = not tap)
*shakenpointer to return the shaken flag (0 = not shaken)
Returns
-1 if failure
int Fin_Buzzer ( int  msec,
int  freq 
)

Fin_Buzzer(msec, freq).

Turn on the buzzer. Use 0,0 to turn the buzzer off

Parameters
msecduration in msecs
freqfrequency in hz
Returns
-1 if failure
int Fin_Exit ( void  )

Fin_Exit(void).

Sends Finch back to idle mode and closes the connection.

Returns
-1 if failure
int Fin_Init ( void  )

Fin_init(void).

Initializes the interface to the finch robot and launches a background thread to prevent the finch from timing out. MUST be called prior to all other finch functions

Returns
-1 if failure
int Fin_LED ( int  red,
int  green,
int  blue 
)

Fin_LED(red, green, blue).

Set the color and intensity of the beak LED

Parameters
redintensity of the red portion of the beak LED (0-255, 0 is off)
greenintensity of the green portion of the beak LED (0-255, 0 is off)
blueintensity of the blue portion of the beak LED (0-255, 0 is off)
Returns
-1 if failure
int Fin_Lights ( int *  left,
int *  right 
)

Fin_Lights(*left, *right).

Get light sensor data. Returned values range from 255 to 0 (0=dark)

Parameters
*leftpointer for left light sensor data
*rightpointer for right light sensor data
Returns
-1 if failure
int Fin_Motor ( int  tenth,
int  left,
int  right 
)

Fin_Motor(tenth, left, right).

Set the speed (and duration) of the wheels. Use 0,0,0 to stop. To set the wheels to spin continuously, set tenth to -1. This function does not block further program execution. Use Fin_Move for that.

Parameters
tenthmotor on time (in tenths of a second)
leftspeed of left wheel (-255 to 255)
rightspeed of right wheel (-255 to 255)
Returns
-1 if failure
int Fin_Move ( int  tenth,
int  left,
int  right 
)

Fin_Move(tenth, left, right).

Set the speed (and duration) of the wheels, and block the program from further execution until time is up. Useful for dancing programs.

Parameters
tenthmotor on time (in tenths of a second)
leftspeed of left wheel (-255 to 255)
rightspeed of right wheel (-255 to 255)
Returns
-1 if failure
int Fin_Obstacle ( int *  left,
int *  right 
)

Fin_Obstacle(*left, *right).

Get obstacle sensor data. Returned value is 1 or 0 (0=no obstacle).

Parameters
*leftpointer for left obstacle sensor data
*rightpointer for right obstacle sensor data
Returns
-1 if failure
int Fin_Speed ( int *  left,
int *  right 
)

Fin_Speed(*left, *right).

Get the current speed of the wheels.

Parameters
*leftpointer to return speed of left wheel
*rightpointer to return speed of right wheel
Returns
-1 if failure
int Fin_Temp ( float *  temp)

Fin_Temp(*temp).

Get temperature sensor data

Parameters
*temppointer to return the temperature; returned value is in celsius (in 1/1000 units)
Returns
-1 if failure
int kbhit ( void  )