added pin change interupt for chaninging animation state

This commit is contained in:
Sean 2022-04-13 21:09:44 -04:00
parent 4f7736b055
commit f2e601bc66
8 changed files with 131 additions and 56 deletions

View file

@ -44,7 +44,7 @@
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| POSSIBILITY OF SUCH DAMAGE. |
\******************************************************************************/
/*********** Modified by S. Dugre to work w/ my hardware***********************/
/*********** Modified by S. Dugre to work w/ my hardware***********************/
#ifndef _CUBEPLEX_H_
#define _CUBEPLEX_H_
@ -577,45 +577,24 @@ byte pinsD[] = {P1D, P2D, P3D, P4D, P5D, P6D, P7D, P8D, P9D, P10D, P11D, P12D, P
#define FULL PWMMMAX
#define HALF PWMMMAX/2
//
// Idea courtesy Ganssle Group. Called from a 5ms timer,
// the debounced state only ever changes when the pin
// has been stable for 40ms. Initialize debounced_state
// to whatever is "inactive" for the system (HIGH or LOW)
//
bool lastButtonState, buttonState = LOW;
uint8_t DebouncePin(uint8_t pin) {
static uint8_t debounced_state = HIGH;
static uint8_t candidate_state = 0;
candidate_state = candidate_state << 1 | digitalRead(pin) & 0x07;
if (candidate_state == 0x07 )
debounced_state = LOW;
else if (candidate_state == 0x00)
debounced_state = HIGH;
return debounced_state;
}
int currentTimer = 0;
int maxTimer = 6250; // 100ms delay / 16uS interrupt time
int nextState(int state) { return (state+1)%2; }
int nextState(int state) {
return (state + 1) % 2;
}
// the interrupt function to display the leds (T2 = 8 bit timer)
ISR(TIMER2_OVF_vect) {
if (not timerReset){
if (not timerReset) {
currentTimer++;
if (currentTimer >= maxTimer) {
timerReset = true;
currentTimer = 0;
}
if (currentTimer >= maxTimer) {
timerReset = true;
currentTimer = 0;
}
}
if (DebouncePin(18)) {
currentState = nextState(currentState);
}
int pin1 = _cube_current_frame->pin1;
int pin2 = _cube_current_frame->pin2;
int count = (pin1 & 0xF0) | ((pin2 & 0xF0) >> 4);
@ -631,7 +610,7 @@ ISR(TIMER2_OVF_vect) {
DDRD = pinsD[pin1] | pinsD[pin2];
PORTB = pinsB[pin1];
PORTC = pinsC[pin1] | B00010000; // sets PC4 to INPUT_PULLUP
PORTC = pinsC[pin1] | B00110000; // sets PC4 & PC5 to INPUT_PULLUP for button
PORTD = pinsD[pin1];
}
@ -642,7 +621,7 @@ ISR(TIMER2_OVF_vect) {
}
}
/**************************Applies to T2 (8 bit timer) only********************\
/**************************Applies to T2 (8 bit timer) only********************\
| Some helpfull info for overflowing timers with different prescaler values |
| 16000000 / ( 1*256) = 16000000 / 256 = 62500 Hz |
| 16000000 / ( 8*256) = 16000000 / 2048 = ~7812 Hz |