Doch nicht sooo großer Schmutz
This commit is contained in:
parent
468e113a30
commit
a3eda7eb86
@ -14,7 +14,7 @@
|
||||
#define HUE_DIF (HUE_MAX - HUE_MIN)
|
||||
#define HUE_SAT 100 // 0 = white, 100 = color
|
||||
#define HUE_VAL 20 // 0 = black, 100 = color
|
||||
#define HUE_STEP 8 // 8
|
||||
#define HUE_STEP 8 // Bis 3 sollte gehen
|
||||
const uint32_t colorSteps = HUE_DIF / HUE_STEP;
|
||||
//~ const uint32_t colorSteps = 5;
|
||||
|
||||
@ -24,6 +24,7 @@ const uint32_t colorSteps = HUE_DIF / HUE_STEP;
|
||||
void writeZero(void);
|
||||
void writeOne(void);
|
||||
void writeRGB(uint8_t red, uint8_t green, uint8_t blue);
|
||||
void nextColor(hsv_t* hsvList, rgb_t* rgbList, hsv_t start, hsv_t end);
|
||||
|
||||
// Interrupt variables:
|
||||
int8_t volatile status = 1;
|
||||
@ -32,28 +33,36 @@ uint16_t volatile max = HUE_MID;
|
||||
uint32_t volatile time = 0;
|
||||
uint32_t volatile T_half = 0;
|
||||
uint32_t volatile oldTime = 0;
|
||||
uint32_t volatile cooldown = 14000000;
|
||||
uint32_t volatile cooldown = 3000000; // * 50 ns = 150 ms disabled interrupt
|
||||
uint8_t volatile triggered = 0;
|
||||
//~ uint32_t volatile delay = 0;
|
||||
|
||||
// On External Interrupt:
|
||||
ISR(INT1_vect) {
|
||||
EIMSK &= 0xfd; // Disable INT1
|
||||
PORTC &= 0xef; // Turn LED off while INT1 disabled
|
||||
uint32_t now = time + TCNT1;
|
||||
//~ triggered = (triggered + 1) % 4;
|
||||
if(now > cooldown) {
|
||||
triggered = true;
|
||||
//~ EIMSK &= 0xfd; // Disable INT1
|
||||
//~ EICRA &= 0xf3; //
|
||||
PORTC &= 0xef; // Turn LED off while INT1 disabled (PORTC3 = PIN26)
|
||||
PORTC ^= 0x02; // toggle LED on INT1 rising edge (PORTC1 = PIN24)
|
||||
//~ uint64_t time2 = TCNT2;
|
||||
//~ uint64_t time1 = TCNT1;
|
||||
//~ uint64_t time0 = TCNT0;
|
||||
//~ T_half = time2 | (time1 << 9) | (time0 << 26);
|
||||
T_half = time + TCNT1;
|
||||
T_half = now;
|
||||
//~ delay = T_half / 16; // Delay for the next possible external interrupt
|
||||
//~ cooldown = T_half / 2;
|
||||
TCNT2 = 0; // Reset Timer/Counter2
|
||||
TCNT1 = 0; // Reset Timer/Counter1
|
||||
cooldown = T_half / 2;
|
||||
//~ TCNT2 = 0; // Reset Timer/Counter2
|
||||
//~ TCNT1 = 0; // Reset Timer/Counter1
|
||||
TCNT0 = 0; // Reset Timer/Counter0
|
||||
time = 0;
|
||||
oldTime = 0;
|
||||
PORTC ^= 0x02;
|
||||
//~ min = HUE_MID;
|
||||
//~ max = HUE_MID;
|
||||
}
|
||||
//~ triggered = 0;
|
||||
min = HUE_MID;
|
||||
max = HUE_MID;
|
||||
//~ status = (status == 1 ? -1 : 1);
|
||||
}
|
||||
|
||||
@ -67,7 +76,7 @@ int main(void) {
|
||||
EIMSK |= 0x02; // External Interrupt Mask Register
|
||||
// Enable INT1 (PIN5) for interrupt
|
||||
EICRA |= 0x0c; // External Interrupt Control Register
|
||||
// INT1 on rising edge
|
||||
// INT1 on falling edge
|
||||
|
||||
TIMSK1 |= 0x01; // Timer/Counter1 Interrupt Mask Register
|
||||
// Enable overflow interrupt
|
||||
@ -125,7 +134,7 @@ int main(void) {
|
||||
}
|
||||
|
||||
// Next color
|
||||
int8_t sign = 1;
|
||||
int8_t sign = -1;
|
||||
min += sign * HUE_STEP;
|
||||
max -= sign * HUE_STEP;
|
||||
interpolate(
|
||||
@ -150,18 +159,19 @@ int main(void) {
|
||||
//~ }
|
||||
|
||||
if(now > cooldown) {
|
||||
EIMSK |= 0x02; // Enable INT1
|
||||
PORTC |= 0x10; // Turn on LED while INT1 enabled
|
||||
//~ EIMSK |= 0x02; // Enable INT1
|
||||
PORTC |= 0x10; // Turn on LED while INT1 enabled (PORTC3 = PIN26)
|
||||
}
|
||||
|
||||
uint32_t T_step = T_half / colorSteps;
|
||||
|
||||
// Check if it is time for next color
|
||||
if(now > oldTime + T_step) {
|
||||
if(now > oldTime) { // + T_step || (now < T_step && oldTime == 0)) {
|
||||
oldTime += T_step;
|
||||
PORTC ^= 0x04;
|
||||
PORTC ^= 0x04; // toggle LED when writing new color (PORTC2 = PIN25)
|
||||
// Assign color
|
||||
//~ EIMSK &= 0xfd; //~ cli();
|
||||
nextColor( colorsHSV, colorsRGB, init_hsv_t(min, HUE_SAT, HUE_VAL), init_hsv_t(max, HUE_SAT, HUE_VAL));
|
||||
for(int i = 0; i < LEDS; i++) {
|
||||
writeRGB( colorsRGB[i].r, colorsRGB[i].g, colorsRGB[i].b);
|
||||
}
|
||||
@ -171,13 +181,14 @@ int main(void) {
|
||||
// Next color
|
||||
min += sign * HUE_STEP;
|
||||
max -= sign * HUE_STEP;
|
||||
interpolate(
|
||||
init_hsv_t(min, HUE_SAT, HUE_VAL), // from color
|
||||
init_hsv_t(max, HUE_SAT, HUE_VAL), // to color
|
||||
LEDS,
|
||||
colorsHSV
|
||||
);
|
||||
hsv2rgbList(colorsHSV, colorsRGB, LEDS);
|
||||
|
||||
//~ interpolate(
|
||||
//~ init_hsv_t(min, HUE_SAT, HUE_VAL), // from color
|
||||
//~ init_hsv_t(max, HUE_SAT, HUE_VAL), // to color
|
||||
//~ LEDS,
|
||||
//~ colorsHSV
|
||||
//~ );
|
||||
//~ hsv2rgbList(colorsHSV, colorsRGB, LEDS);
|
||||
// Check if reached amplitude
|
||||
if(sign == 1 && (min >= HUE_MAX || max <= HUE_MIN)) {
|
||||
sign = -1;
|
||||
@ -197,6 +208,15 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void inline nextColor(hsv_t* hsvList, rgb_t* rgbList, hsv_t start, hsv_t end) {
|
||||
interpolate(start, // from color
|
||||
end, // to color
|
||||
LEDS,
|
||||
hsvList
|
||||
);
|
||||
hsv2rgbList(hsvList, rgbList, LEDS);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* TIMING
|
||||
|
Loading…
Reference in New Issue
Block a user