Instructables

Step 10: Software

Picture of Software
You can grab the binary here, or the full source right here. Instructions on how to program your Propeller Platform in Windows, Linux, or Mac are here. You can also use the audio samples I've created right here. Download them and copy to the root of your microSD card. Here's an overview of how the program works, which you'll find especially useful if you want to customize it;

Main Loop

the main program runs through this code, checking for a reason to play a sample;

Repeat

seatstatus := seatposition
lightstatus := checklight
IF (lightstatus == 1 AND seatstatus == 1)

playaudio(string("cover.wav"))

IF (lightstatus == 0 AND seatstatus == 1)

playaudio(string("seat.wav"))

IF (lightstatus == 3 AND seatstatus == 0)

playaudio(string("light.wav"))

First, it runs the method seatposition and stores the value returned in the variable seatstatus. Then it does the same thing with checklight, storing the returned value in lightstatus.

If lightstatus == 1 and seatstatus == 1, the seat is up and the light is on. Toilet buddy goes ahead and plays cover.wav. If the light is off and the seat is up, seat.wav is played.

If lightstatus == 3, that means the light timeout has been reached. Then it plays the light.wav file.

checklight

This method checks if the bathroom light is on. It uses the rctime object (part of the Propeller Tool download) to accomplish that. It charges up the capacitor connected to the photoresistor and counts how long it takes to discharge with a single line;

RC.RCTIME(phresistor,1,@RCValue)

The variable RCValue will store the discharge time. If it's greater than the limit we set, that means not very much light is hitting the photoresistor, and we return 0. If more light is hitting it, we increment the light timer and return 1, until we reach the light timer limit.

seatposition

We check the status of the seat with this method. We use ir object to accomplish this, which is also part of the Propeller Tool download. First, we have to tell the ir method what pins the IR LED and receiver are connected to - we do this at the beginning of the program with;

ir.init(IRAnode, IRCathode, IRSensor)

Then, when we call ir.distance, it will return the measured distance of an object in front of the sensor.

playaudio

This method actually takes care of the audio playback. It's a simplified version of rayman's wav player. First, it opens up the file we requested. Then it reads the header to see if the wav file is 44khz or 48khz. Then it starts up the wav player in a second core. Our first core then fills the audio buffer for the second core.

The important thing to keep in mind is this player will only playback 16-bit stereo wavs. Also, the headers on the wav file need to be empty so the player can find the sample rate.
 
Remove these adsRemove these ads by Signing Up
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!