diff --git a/sketches/input/input.c b/sketches/input/input.c index c367563..160dad0 100644 --- a/sketches/input/input.c +++ b/sketches/input/input.c @@ -8,11 +8,45 @@ //~ #include #include -uint8_t volatile status = 0; +#define HUE_MAX 610 +#define HUE_MIN 350 +#define STEPS 8 +//~ const uint32_t colorSteps = (HUE_MAX - HUE_MIN) / STEPS; +const uint32_t colorSteps = 5; -ISR(INT1_vect){ +uint8_t volatile status = 0; +uint32_t volatile time = 0; +uint32_t volatile T_half = 0; +uint32_t volatile oldColor = 0; +uint32_t volatile oldTime = 0; + +//~ ISR(INT0_vect) { + //~ status = 1; + //~ T_half = time + TCNT1; + //~ TCNT1 = 0; // Reset Timer/Counter1 + //~ time = 0; + //~ PORTC += 1; + //~ PORTC ^= 0x04; + +//~ } + +ISR(INT1_vect) { status = 1; - //~ PCORT0 = 1; + T_half = time + TCNT1; + TCNT1 = 0; // Reset Timer/Counter1 + time = 0; + oldColor = 0; + oldTime = 0; + PORTC ^= 1; + PORTC &= 0x01; + //~ PORTC ^= 0x04; + +} + +ISR(TIMER1_OVF_vect) { + time += 0x00010000; + //~ PORTC += 1; + //~ PORTC ^= 0x04; } int main(){ @@ -20,11 +54,16 @@ int main(){ //~ PORTD |= (1 << PORTD2); // turn On the Pull-up // PD2 is now an input with pull-up enabled + + EIMSK |= 0x02; // External Interrupt Mask Register + // Enable INT1 (PIN5) for interrupt + EICRA |= 0x0c; // External Interrupt Control Register + // INT1 on rising edge - EICRA |= 0x0F; // External Interrupt Control Register - // INT0 on rising edge - EIMSK |= 0x03; // External Interrupt Mask Register - // Enable INT0 for interrupt + TIMSK1 |= 0x01; // Timer/Counter1 Interrupt Mask Register + // Enable overflow interrupt + TCCR1B |= 0x01; // Timer/Counter1 Control Register B + // Prescale Factor 1 SREG |= 0x80; // Status Register // Enable global interrupts @@ -35,16 +74,25 @@ int main(){ //~ PCMSK2 = 0xff; // Pin Change Mask Register 2 //~ // Enabled PCINT[23;16] (Single Pins) - DDRC = 0xff; + DDRC = 0x3f; + PORTC = 0x00; - while(1){ - if(status){ - PORTC ^= 0x01; - status = 0; + while(1) { + uint32_t T_step = T_half / colorSteps; + //~ uint32_t colorStep = (time + TCNT1) / T_step; + + //~ if (colorStep > oldColor) { + //~ // TODO next color + //~ PORTC += 0x02; + //~ oldColor = colorStep; + //~ } + + if(time + TCNT1 > oldTime + T_step){ + oldTime += T_step; + PORTC += 0x02; } - PORTC ^= 0x02; } return 0; } diff --git a/sketches/input/input_orig.cc b/sketches/input/input_orig.cc new file mode 100644 index 0000000..c367563 --- /dev/null +++ b/sketches/input/input_orig.cc @@ -0,0 +1,50 @@ +#include +#include +#include +#define F_CPU 20000000UL +#include +#include +//~ #define BAUD 9600 +//~ #include +#include + +uint8_t volatile status = 0; + +ISR(INT1_vect){ + status = 1; + //~ PCORT0 = 1; +} + +int main(){ + + //~ PORTD |= (1 << PORTD2); // turn On the Pull-up + // PD2 is now an input with pull-up enabled + + + EICRA |= 0x0F; // External Interrupt Control Register + // INT0 on rising edge + EIMSK |= 0x03; // External Interrupt Mask Register + // Enable INT0 for interrupt + + SREG |= 0x80; // Status Register + // Enable global interrupts + + //~ PCICR |= 0x04; // Pin Change Interrupt Control Register + //~ // Enabled PCINT[23;16] -> Pin 13,12,11,6,5,4,3,2 + //~ PCIFR |= 0x04; // Pin Change Interrupt Flag Register + + //~ PCMSK2 = 0xff; // Pin Change Mask Register 2 + //~ // Enabled PCINT[23;16] (Single Pins) + DDRC = 0xff; + + + + while(1){ + if(status){ + PORTC ^= 0x01; + status = 0; + } + PORTC ^= 0x02; + } + return 0; +} diff --git a/sketches/input/input_orig.o b/sketches/input/input_orig.o new file mode 100755 index 0000000..f68d558 Binary files /dev/null and b/sketches/input/input_orig.o differ