Learn to program

 
  Finch assignments ::

Learning Goal: Understand how to write a program to control a robot, using loops, conditionals and subroutines where appropriate.

 

 
 

Finch Assignment 15 (optional) - Temperature sensor and Accelerometer

 

finch hardware

 Temperature. The Finch has a single thermistor sensor that detects the ambient temperature.
The sensor can also determine the temperature of an object if the object is placed in contact with
the sensor. The temperature sensor is accurate to within 2 degrees Fahrenheit.

The command temperature() returns the temperature in degrees Celsius.

You use this by declaring a variable, for example, my_temp

my_temp = xfinch.temperature()

 

Accelerometers. The Finch uses a Freescale MMA7660FC 3-axis MEMS accelerometer to detect acceleration.
The sensor can detect accelerations of +/- 1.5 gees. The primary use of the accelerometer is to detect the
direction of gravity, so as to know how the Finch is oriented (flat on the ground, upright, etc). It is also
possible to detect spikes in acceleration caused by tapping or shaking the Finch.

The command acceleration returns (x,y,z,tap,shake)

x, y and z are the acceleration readings in units of Gs, and range from -1.5 to 1.5

When the Finch is horizontal, Z is close to 1, x and y close to 0.

When the Finch stands on its tail, y and z are close to 0, x is close to -1.

When the Finch is held with the left wing down, x and z are close to 0, y is close to 1.

tap, shake are Boolean values - true of the corresponding event has happened.

 

You use this by declaring a variable, for example, action

action = xfinch.acceleration

 

Assignment 15:

Write a program to make the Finch's nose turn red if the temperature is above 31 C ( your body temperature is 37 C).

Its nose should turn blue if the Finch is standing on its tail, green if it is horizontal,

and yellow if it is being shaken.

 

Turn the program in to Shared - Student - Pereira - AI 201x - Class color - Finch assignments - 15 Final
as finalyourname.

 

Write a Reflection on what you have learned.

 

To make the Finch play sounds through the computer:

In the beginning of your program, add a line: import winsound

Then, to play a musical note, the command is winsound.Beep(frequency, duration),

The frequency parameter specifies frequency, in hertz, of the sound, and must be in the range 37 through 32,767.
You can find frequencies here.

Duration is in milliseconds, so one second will be inserted as 1000

You will need to borrow speakers from me.