Bryce Williams / FivePosSwitch

Fork of FivePosSwitch by Bryce Williams

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FivePosSwitch.h Source File

FivePosSwitch.h

00001 /*
00002     Bryce Williams 
00003     10/04/2015
00004     
00005     Library for modified Sparkfun 5- Way Tact Switch Breakout (Part# BOB-11187)
00006     
00007         Breakout Board Mod: Remove the 10k pull- up resistors. This will make 
00008                             the board a basic breakout for the 5-Way switch. 
00009                             The Vcc pin (+) can be clipped or left unimplented
00010                             (i.e. no connect). 
00011  
00012         Circuit Setup:
00013                                    Vcc 
00014                                    | 
00015             ----------------       |                                ----------
00016             |  5- Way   (-)|-------|                                | mBed    |
00017             |              |        40.0k                           |         |  
00018             |  Tact     (R)|--------vvv--------|                    |         |  
00019             |              |        15.0k      |                    |         | 
00020             |  Switch   (D)|--------vvv--------|                    |         |
00021             |              |        6.67k      |                    |         |  
00022             |           (L)|--------vvv--------|--------------------|AnalogIn |    
00023             |              |        2.5k       |        |           |         |  
00024             |           (C)|--------vvv--------|        >           |         |  
00025             |              |                   |        > 10k       |         |  
00026             |           (U)|-------------------|        >           |         |  
00027             |              |                            |           |---------
00028             |           (+)|-----------X               --- 
00029             ----------------                           GND
00030         
00031         Theory of Operation: Each switch output pin is connected to one terminal of
00032                             a resistor (each of different value). The other terminal 
00033                             is connected to a single analog in pin on the mBed. 
00034                             The mBed analog pin is also connected to a 10k resistor
00035                             running to ground. This makes a network of seperate 
00036                             voltage dividers, between each switches output pin 
00037                             resistor and the single 10k resistor from the mBed
00038                             analog in pin to ground. Since only one position can 
00039                             be active at a time only one voltage divider voltage 
00040                             is read by the mBed. Thus each switch position produces
00041                             a unique voltage, at the analog in pin of the mBed,
00042                             when active.
00043                             
00044         NOTE: For proper operation resistor values should be as close as POSSIBLE
00045               to those shown in the circuit setup diagram!                        
00046 */
00047 #ifndef FIVE_POS_SWITCH
00048 #define FIVE_POS_SWITCH
00049 #include "mbed.h"
00050 
00051 enum ACTIVE_POSITION{NONE = 0, UP = -1, CENTER = -2, LEFT = -3, DOWN = -4, RIGHT = -5};
00052 
00053 class FivePosSwitch{
00054     public:
00055         /** Constructor for FivePosSwitch
00056             @param <pin> The AnalogIn Pin
00057         */ 
00058         FivePosSwitch(AnalogIn pin);
00059         /** Get the currently pressed switch position
00060             @return The currently pressed switch position 
00061         */
00062         ACTIVE_POSITION getPosition();
00063     private:
00064         AnalogIn _pin;
00065         static const float TOLERANCE = 0.075;     // Allowable tolerance in evaluating for active switch
00066                                                   // (0.075 will give a 0.05 deadband between posistions)
00067 };
00068 
00069 #endif