Overview
This page talks about the Arduino library functions and methods as well as how to talk to the drink shield through the drink shield protocol. This will allow your games or devices to stay compatible with the standard drink shield firmware. If you need more options feel free to submit them to the project. To be added to the subversion project send email to [email protected].
Arduino Library Methods
DrinkShield ds(0,1) – Initialization of the drink shield. The two numbers that are passed to the DrinkShield object are the major and minor version number printed on the board itself. If the version number is 0.1 then you pass 0, 1. ds can be any varable name you want.
version – Retuns the version of the firmware in the format “DrinkShield vX.X”
playerReady – Returns player ready status. 0 = Not Ready, 1 = Ready
refreshLights() - Refreshes the lights. This is primarily an internal call but can be used if you really want to.
updatePlayerLights() – Updates the player ready lights based on the playerReady state.
setPlayerLights(int notReady, int Ready) – Sets the player ready lights. You should use the constants ON/OFF to set these lights. This is a convenience function for setting the green and red lights individually.
redLigth(int state) – Turns on/off the red Player not ready light. NOTE: Does not affect the actual player ready state.
greenLight(int state) - turns on/off the green Player ready light. NOTE: Does not affect the actual player ready state.
lightBarLevel(int height, int highLED) – Sets the light bar level. This will light up the lights starting at 0 up to the specified height. if highLED is > 0 then it will also turn on that LED. This is useful to show the current reading via height and the highest reading via highLED.
lightTest() – Does a simple light bar test to ensure your lights are working.
pollSerial() - Checks for serial input from a connected device and processes it based on the DrinkShield protocol specified below.
autocalibrate(int samples) – This will take X number of air samples to determine a baseline. There is always alcohol present in the air around you and it varies based on lots of factors so it is possible to autocalibrate whenever you need to. A good default sample amount is usually 20. Using this method prevents the need to use hardware to calibrate the MQ-3 and can expand the lifetime of the sensor. You should always run this during setup.
int getReading() – Returns and integer value if the current sensor reading is above the baseline determined by autocalibration. If the current reading isn’t above the determine baseline thena 0 is returned.
bool isClear() – Simple function that returns a 1 if the MQ-3 is currently not returning a reading above the baseline and a 1 if there is still alcohol being detected. Sometimes it can take a while for the sensor to clear out.
int getLightLevel(int value) - Given a value returned from getReading() this method will return the level of LEDs that value corresponds to. For instance if you have 11 lights in your lightbar and you pass this method a value of 243 it may return a 6 to reflect the position in the lightbar for that value.
DrinkShield Protocol
This section defines the Serial communication you can use to talk to the drink Shield. NOTE: You must initialize Serial.begin(9600) in setup() as well and insert ds.pollEvents() in your main loop().
Also in setup you should print out the drink shield firmware version. This allows the connected software to adjust to changes that may occur in the future.
Example: Serial.println(ds.version);
All commands are ONE character inputs but can be multiple character outputs from the drinkShield and will always in with a \n.
Initialize
INPUT: i
OUTPUT: firmware version info (Eg: DrinkShield v0.3)
Player Ready
INPUT: r
OUTPUT: Blow!
Auto-calibrate
INPUT: a
OUTPUT: none
Light test
INPUT: l
OUTPUT: none
Abort Player Ready
INPUT: A
OUTPUT: none
Notes
You can look at the code for the DrinkDuino Game for complex examples. You can also experiment with the Arduino serial monitor or simply by using echo or tail commands to /dev/ttyUSB0