11/* ******************************************************************************************************************
22** This program defines the RotaryEncoder class. See the "Encoder.h" file for program documentation **
33*******************************************************************************************************************/
4- #include " Encoder .h" // Include the header file //
4+ #include " RotaryEncoder .h" // Include the header file //
55EncoderClass* EncoderClass::ClassPtr; // Declare Class Reference pointer //
66/* ******************************************************************************************************************
77** 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; //
1010** pointer to the class with an offset to the appropriate function to call the correct function. **
1111*******************************************************************************************************************/
1212EncoderClass::EncoderClass (const uint8_t LeftPin, const uint8_t RightPin, // Class constructor //
13- const uint8_t PushbuttonPin, const uint8_t RedPin, // //
14- const uint8_t GreenPin, const uint8_t BluePin ) : // //
13+ const uint8_t PushbuttonPin, // //
14+ const uint8_t RedPin=255 ,const uint8_t GreenPin=255 ,// //
15+ const uint8_t BluePin=255 ) : // //
1516 _LeftPin(LeftPin), _RightPin(RightPin), _PushbuttonPin(PushbuttonPin), // //
1617 _RedPin(RedPin), _GreenPin(GreenPin), _BluePin(BluePin) { // //
1718 pinMode (RedPin,OUTPUT); pinMode (GreenPin,OUTPUT); pinMode (BluePin,OUTPUT); // Set LED color pins to output //
18- analogWrite (RedPin,255 );analogWrite (GreenPin,255 );analogWrite (BluePin,255 ); // Ensure LEDs are off at start //
19+ if (RedPin!=255 ) analogWrite (RedPin,255 ); // If the LED pins are defined, //
20+ if (GreenPin!=255 ) analogWrite (GreenPin,255 ); // then turn them off at the start //
21+ if (BluePin!=255 ) analogWrite (BluePin,255 ); // //
1922 pinMode (LeftPin, INPUT); // Define encoder pins as input //
2023 pinMode (RightPin, INPUT); // Define encoder pins as input //
2124 pinMode (PushbuttonPin, INPUT); // Define pushbutton pin as input //
2225 digitalWrite (LeftPin, HIGH); // Turn the pull-up resistor on //
2326 digitalWrite (RightPin, HIGH); // Turn the pull-up resistor on //
2427 _EncoderValue = 0 ; // Reset in case it was changed //
25- ClassPtr = this ; // pointer to current instance //
28+ ClassPtr = this ; // pointer to current instance //
2629 attachInterrupt (digitalPinToInterrupt (LeftPin),RotateISR,CHANGE); // Attach static internal function //
2730 attachInterrupt (digitalPinToInterrupt (RightPin),RotateISR,CHANGE); // Attach static internal function //
2831 attachInterrupt (digitalPinToInterrupt (PushbuttonPin),PushButtonISR,RISING); // Attach static internal function //
29- SetFade (true ); // turn on fader and interrupt //
32+ if (RedPin|GreenPin|BluePin==255 ) SetFade (false ); // If no LEDs, turn off fader //
33+ else SetFade (true ); // turn on fader and interrupt //
3034} // of class constructor // //
3135ISR (TIMER0_COMPA_vect) {EncoderClass::TimerISR ();} // Call the ISR every millisecond //
3236static void EncoderClass::PushButtonISR (){ClassPtr->PushButtonHandler ();} // Redirect to real handler function//
0 commit comments