diff --git a/Examples/StandardColors/StandardColors.ino b/Examples/StandardColors/StandardColors.ino index b48dae3..ede6269 100644 --- a/Examples/StandardColors/StandardColors.ino +++ b/Examples/StandardColors/StandardColors.ino @@ -1,5 +1,8 @@ /******************************************************************************************************************* -** This program defines the RotaryEncoder class header. ** +** This program defines the RotaryEncoder class header. It is published on GitHub and full description of the ** +** class as well as the public function descriptions can be found at the GitHub wiki pages located at: ** +** ** +** https://github.com/SV-Zanshin/RotaryEncoder/wiki ** ** ** ** This program demonstrates the Rotary Encoder class which controls a commonly used rotary encoder with a clear ** ** knob using 3 colored LEDs (Red, Green and Blue) along with a pushbutton. These are available from sources such ** @@ -24,17 +27,18 @@ ** ** ** Vers. Date Developer Comments ** ** ====== ========== =================== ======================================================================== ** +** 1.0.0 2016-12-14 Arnd@SV-Zanshin.Com Changed include from "Encoder" to "RotaryEncoder", added comments ** ** 1.0.0 2016-12-13 Arnd@SV-Zanshin.Com Initial coding ** ** ** *******************************************************************************************************************/ -#include // Include Encoder library // +#include // Include Encoder library // //----------------------------------// const uint8_t ROTARY_PIN_1 = 2; // Pin for left rotary encoder pin // const uint8_t ROTARY_PIN_2 = 3; // Pin for right rotary encoder pin // const uint8_t PUSHBUTTON_PIN = 7; // Pin for pushbutton connector pin // -const uint8_t RED_PIN = 11; // Red LED PWM pin. This is grounded// -const uint8_t GREEN_PIN = 10; // Green LED PWM pin. Grounded // -const uint8_t BLUE_PIN = 9; // Blue LED PWM pin. Grounded // +const uint8_t RED_PIN = 11; // Red LED PWM pin. Ground = FULL // +const uint8_t GREEN_PIN = 10; // Green LED PWM pin. Ground = FULL // +const uint8_t BLUE_PIN = 9; // Blue LED PWM pin. Ground = FULL // //----------------------------------// EncoderClass Encoder(ROTARY_PIN_1, ROTARY_PIN_2, PUSHBUTTON_PIN, // Instantiate class defining all // RED_PIN, GREEN_PIN, BLUE_PIN); // of the pins that are used // @@ -43,8 +47,8 @@ void setup() { // Serial.begin(115200); // Initialize Serial I/O at speed // delay(1000); // Wait 1 second for initialization // Serial.println("Starting Encoder Program..."); // // -} // of method setup() //----------------------------------// - +} // of method setup() // // + //----------------------------------// void loop(){ // Main program infinite loop // static int last = Encoder.GetEncoderValue(); // Store previous Encoder value // uint8_t presses = Encoder.GetButton(); // See how often button was pressed // diff --git a/Encoder.cpp b/RotaryEncoder.cpp similarity index 95% rename from Encoder.cpp rename to RotaryEncoder.cpp index bc8d346..02fb255 100644 --- a/Encoder.cpp +++ b/RotaryEncoder.cpp @@ -1,7 +1,7 @@ /******************************************************************************************************************* ** This program defines the RotaryEncoder class. See the "Encoder.h" file for program documentation ** *******************************************************************************************************************/ -#include "Encoder.h" // Include the header file // +#include "RotaryEncoder.h" // Include the header file // EncoderClass* EncoderClass::ClassPtr; // Declare Class Reference pointer // /******************************************************************************************************************* ** The class constructor stores the pin values as part of the initializer and then uses an indirect method to ** @@ -10,23 +10,27 @@ EncoderClass* EncoderClass::ClassPtr; // ** pointer to the class with an offset to the appropriate function to call the correct function. ** *******************************************************************************************************************/ EncoderClass::EncoderClass(const uint8_t LeftPin, const uint8_t RightPin, // Class constructor // - const uint8_t PushbuttonPin, const uint8_t RedPin, // // - const uint8_t GreenPin, const uint8_t BluePin ) : // // + const uint8_t PushbuttonPin, // // + const uint8_t RedPin=255,const uint8_t GreenPin=255,// // + const uint8_t BluePin=255 ) : // // _LeftPin(LeftPin), _RightPin(RightPin), _PushbuttonPin(PushbuttonPin), // // _RedPin(RedPin), _GreenPin(GreenPin), _BluePin(BluePin) { // // pinMode(RedPin,OUTPUT); pinMode(GreenPin,OUTPUT); pinMode(BluePin,OUTPUT); // Set LED color pins to output // - analogWrite(RedPin,255);analogWrite(GreenPin,255);analogWrite(BluePin,255); // Ensure LEDs are off at start // + if (RedPin!=255) analogWrite(RedPin,255); // If the LED pins are defined, // + if (GreenPin!=255) analogWrite(GreenPin,255); // then turn them off at the start // + if (BluePin!=255) analogWrite(BluePin,255); // // pinMode(LeftPin, INPUT); // Define encoder pins as input // pinMode(RightPin, INPUT); // Define encoder pins as input // pinMode(PushbuttonPin, INPUT); // Define pushbutton pin as input // digitalWrite(LeftPin, HIGH); // Turn the pull-up resistor on // digitalWrite(RightPin, HIGH); // Turn the pull-up resistor on // _EncoderValue = 0; // Reset in case it was changed // - ClassPtr = this; // pointer to current instance // + ClassPtr = this; // pointer to current instance // attachInterrupt(digitalPinToInterrupt(LeftPin),RotateISR,CHANGE); // Attach static internal function // attachInterrupt(digitalPinToInterrupt(RightPin),RotateISR,CHANGE); // Attach static internal function // attachInterrupt(digitalPinToInterrupt(PushbuttonPin),PushButtonISR,RISING); // Attach static internal function // - SetFade(true); // turn on fader and interrupt // + if (RedPin|GreenPin|BluePin==255) SetFade(false); // If no LEDs, turn off fader // + else SetFade(true); // turn on fader and interrupt // } // of class constructor // // ISR(TIMER0_COMPA_vect) {EncoderClass::TimerISR();} // Call the ISR every millisecond // static void EncoderClass::PushButtonISR(){ClassPtr->PushButtonHandler();} // Redirect to real handler function// diff --git a/Encoder.h b/RotaryEncoder.h similarity index 96% rename from Encoder.h rename to RotaryEncoder.h index c74d4e1..7584431 100644 --- a/Encoder.h +++ b/RotaryEncoder.h @@ -37,19 +37,20 @@ ** ** ** Vers. Date Developer Comments ** ** ====== ========== =================== ======================================================================== ** +** 1.0.1 2016-12-14 Arnd@SV-Zanshin.Com Allowed defaults for LEDs on class constructer ** ** 1.0.b3 2016-12-13 Arnd@SV-Zanshin.Com Made fading start only after the maximum setting was reached ** ** 1.0.b2 2016-12-12 Arnd@SV-Zanshin.Com Fixed interrupt calls ** ** 1.0.b1 2016-12-04 Arnd@SV-Zanshin.Com Initial coding ** ** ** *******************************************************************************************************************/ #include "Arduino.h" // Arduino data type definitions // -#ifndef Encoder_h // Guard code definition // - #define Encoder_h // Define the name inside guard code// +#ifndef RotaryEncoder_h // Guard code definition // + #define RotaryEncoder_h // Define the name inside guard code// class EncoderClass { //----------------------------------// public: // Publicly visible class members // EncoderClass(const uint8_t LeftPin, const uint8_t RightPin, // Class constructor // - const uint8_t PushbuttonPin, const uint8_t RedPin, // // - const uint8_t GreenPin,const uint8_t BluePin); // // + const uint8_t PushbuttonPin, const uint8_t RedPin=255, // // + const uint8_t GreenPin=255,const uint8_t BluePin=255); // // uint8_t GetButton(); // Returns number of button pushes // int16_t GetEncoderValue(); // Return the encoder value // void SetEncoderValue(const int16_t NewValue = 0); // Set the encoder value //