You are viewing an older revision! See the latest version
Project Overview
Overview¶
The aim of this project is to create a working clock using FRDM-KL25Z and necessary components while also exploring the use of distance sensors as input (control pannel) and possible game ideas with the use multiple screens.
Clock¶
Distance Sensors¶
Setup¶
We're using tobeaddedlater as the distance sensor. Using this MaxSonar library, one can quickly get the sensor up and running. The library contains the MaxSonar class with an example of the setup:
MaxSonar Example
#include "mbed.h" #include "MaxSonar.h " int main() { MaxSonar *range; float r; // Create and configure object for 3.3V powered LV-series device, // accessed with analog reads (in cm) on p16, triggered by p7. range = new MaxSonar(MS_LV, MS_ANALOG, p7, p16); range->setVoltage(3.3); range->setUnits(MS_CM); while(1) { // Trigger read, wait 49ms until ranger finder has // finished, then read. range->triggerRead(); wait_ms(49); r = range->read(); // Print and delay 0.5s. printf("Range: %.3f cm\n", r); wait(0.5); } }
Connect Vcc to 3.3V; Vss to ground; Tx to a digital pin on the mbed (this is the trigger pin - p7 in the code above); And the analog pin to an analog pin on the mbed (this p16 in the code above).
Distance Sensors an input¶
This device is crucial to the build in games for the clock. To demonstrate this, lets look at the code for the game option menu and see how one can use two distance senor to select and run the game.
Game Menu
void GameOption() { ClearAllScreen(); UpdateScreen(questionScreen, "Select a game: >" + gameName[gameOptionLocation]); bool gameOption = true; while(gameOption) { UpdateRange(); if(r1 < 25 && r2 < 25) { UpdateScreen(questionScreen, "Entering " + gameName[gameOptionLocation] + "....."); wait(1); gameOption = false; } else if(r1 < 20) { if(gameOptionLocation > 0) { gameOptionLocation--; UpdateScreen(questionScreen, "Select a game: >" + gameName[gameOptionLocation]); } } else if(r2 < 20) { if(gameOptionLocation < 1) { gameOptionLocation++; UpdateScreen(questionScreen, "Select a game: >" + gameName[gameOptionLocation]); } } } StartGame(gameOptionLocation); }