Rotary encoder library.

Dependents:   RotaryEncoder_TestProgram ST7735_Pong accuBlast_display

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RotaryEncoder.h Source File

RotaryEncoder.h

00001 /**
00002  * =============================================================================
00003  * Rotary Encoder class (Version 0.0.1)
00004  * =============================================================================
00005  * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a copy
00008  * of this software and associated documentation files (the "Software"), to deal
00009  * in the Software without restriction, including without limitation the rights
00010  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011  * copies of the Software, and to permit persons to whom the Software is
00012  * furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included in
00015  * all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023  * THE SOFTWARE.
00024  * =============================================================================
00025  */
00026 
00027 #ifndef ROTARY_ENCODER_H
00028 #define ROTARY_ENCODER_H
00029 
00030 #include "mbed.h"
00031 
00032 /**
00033  */
00034 class RotaryEncoder {
00035 public:
00036     /**
00037      * Create rotary encoder.
00038      *
00039      * @param pin1_name
00040      * @param pin2_name
00041      * @param min Minimum value.
00042      * @param max Maximum value.
00043      * @param val Default value.
00044      */
00045     RotaryEncoder(PinName pin1_name, PinName pin2_name, int min = 0, int max = 100, int val = 50);
00046 
00047     /**
00048      * Dispose.
00049      */
00050     ~RotaryEncoder();
00051 
00052     /**
00053      * Get the minimum value.
00054      *
00055      * @return The minimum value.
00056      */
00057     int getMin() const {
00058         return min;
00059     }
00060 
00061     /**
00062      * Get the maximum value.
00063      *
00064      * @return The maximum value.
00065      */
00066     int getMax() const {
00067         return max;
00068     }
00069 
00070     /**
00071      * Get the value.
00072      *
00073      * @param The value.
00074      */
00075     int getVal() const {
00076         return val;
00077     }
00078 
00079 private:
00080     DigitalIn pin1;
00081     DigitalIn pin2;
00082     const int min;
00083     const int max;
00084     int val;
00085     Ticker ticker;
00086 
00087     /**
00088      * Internal tick function.
00089      */
00090     void func_ticker();
00091 };
00092 
00093 #endif