1
1
/* ******************************************************************************************************************
2
2
** This program defines the RotaryEncoder class. See the "Encoder.h" file for program documentation **
3
3
*******************************************************************************************************************/
4
- #include " Encoder .h" // Include the header file //
4
+ #include " RotaryEncoder .h" // Include the header file //
5
5
EncoderClass* EncoderClass::ClassPtr; // Declare Class Reference pointer //
6
6
/* ******************************************************************************************************************
7
7
** 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; //
10
10
** pointer to the class with an offset to the appropriate function to call the correct function. **
11
11
*******************************************************************************************************************/
12
12
EncoderClass::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 ) : // //
15
16
_LeftPin(LeftPin), _RightPin(RightPin), _PushbuttonPin(PushbuttonPin), // //
16
17
_RedPin(RedPin), _GreenPin(GreenPin), _BluePin(BluePin) { // //
17
18
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 ); // //
19
22
pinMode (LeftPin, INPUT); // Define encoder pins as input //
20
23
pinMode (RightPin, INPUT); // Define encoder pins as input //
21
24
pinMode (PushbuttonPin, INPUT); // Define pushbutton pin as input //
22
25
digitalWrite (LeftPin, HIGH); // Turn the pull-up resistor on //
23
26
digitalWrite (RightPin, HIGH); // Turn the pull-up resistor on //
24
27
_EncoderValue = 0 ; // Reset in case it was changed //
25
- ClassPtr = this ; // pointer to current instance //
28
+ ClassPtr = this ; // pointer to current instance //
26
29
attachInterrupt (digitalPinToInterrupt (LeftPin),RotateISR,CHANGE); // Attach static internal function //
27
30
attachInterrupt (digitalPinToInterrupt (RightPin),RotateISR,CHANGE); // Attach static internal function //
28
31
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 //
30
34
} // of class constructor // //
31
35
ISR (TIMER0_COMPA_vect) {EncoderClass::TimerISR ();} // Call the ISR every millisecond //
32
36
static void EncoderClass::PushButtonISR (){ClassPtr->PushButtonHandler ();} // Redirect to real handler function//
0 commit comments