Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/STAR_momentary.c b/STAR_momentary.c
- index 1cbed87..4502b36 100644
- --- a/STAR_momentary.c
- +++ b/STAR_momentary.c
- @@ -72,11 +72,12 @@
- */
- #define VOLTAGE_MON // Comment out to disable - ramp down and eventual shutoff when battery is low
- -#define MODES 0,3,14,39,125,255 // Must be low to high, and must start with 0
- -#define ALT_MODES 0,3,14,39,125,255 // Must be low to high, and must start with 0, the defines the level for the secondary output. Comment out if no secondary output
- -#define MODE_PWM 0,PHASE,FAST,FAST,FAST,PHASE // Define one per mode above. 0 tells the light to go to sleep
- -#define TURBO // Comment out to disable - full output with a step down after n number of seconds
- - // If turbo is enabled, it will be where 255 is listed in the modes above
- +#define MODES 0,3,14,39,125,255,TURBO // Must be low to high, and must start with 0
- +#define ALT_MODES 0,3,14,39,125,255,0 // Must be low to high, and must start with 0, the defines the level for the secondary output. Comment out if no secondary output
- +#define MODE_PWM 0,PHASE,FAST,FAST,FAST,PHASE,PHASE // Define one per mode above. 0 tells the light to go to sleep
- +#define TURBO 254 // Convenient define for the turbo level in MODES above.
- + // full output with a step down after n number of seconds if TURBO_TIMEOUT is defined.
- + // This is not defined to 255 so that value remains a valid PWM choice in MODES.
- #define TURBO_TIMEOUT 5625 // How many WTD ticks before before dropping down (.016 sec each)
- // 90 = 5625
- // 120 = 7500
- @@ -103,7 +104,8 @@
- #include <avr/sleep.h>
- //#include <avr/power.h>
- -#define STAR3_PIN PB4 // If not connected, will cycle L-H. Connected, H-L
- +#define LOW_TO_HIGH 1 // If 1, will cycle L-H. If 0, H-L
- +#define FET_PIN PB4
- #define SWITCH_PIN PB3 // what pin the switch is connected to, which is Star 4
- #define PWM_PIN PB1
- #define ALT_PWM_PIN PB0
- @@ -140,7 +142,6 @@ const uint8_t alt_modes[] = { ALT_MODES };
- const uint8_t mode_pwm[] = { MODE_PWM };
- volatile uint8_t mode_idx = 0;
- volatile uint8_t press_duration = 0;
- -volatile uint8_t low_to_high = 0;
- volatile uint8_t in_momentary = 0;
- // Debounce switch press value
- @@ -288,7 +289,7 @@ ISR(WDT_vect) {
- if (press_duration == LONG_PRESS_DUR) {
- // Long press
- - if (low_to_high) {
- + if (LOW_TO_HIGH) {
- prev_mode();
- } else {
- next_mode();
- @@ -318,15 +319,15 @@ ISR(WDT_vect) {
- // Not pressed
- if (press_duration > 0 && press_duration < LONG_PRESS_DUR) {
- // Short press
- - if (low_to_high) {
- + if (LOW_TO_HIGH) {
- next_mode();
- } else {
- prev_mode();
- }
- } else {
- // Only do turbo check when switch isn't pressed
- - #ifdef TURBO
- - if (modes[mode_idx] == 255) {
- + #ifdef TURBO_TIMEOUT
- + if (modes[mode_idx] == TURBO) {
- turbo_ticks++;
- if (turbo_ticks > TURBO_TIMEOUT) {
- // Go to the previous mode
- @@ -372,16 +373,16 @@ int main(void)
- {
- // Set all ports to input, and turn pull-up resistors on for the inputs we are using
- DDRB = 0x00;
- - PORTB = (1 << SWITCH_PIN) | (1 << STAR3_PIN);
- + PORTB = (1 << SWITCH_PIN);
- // Set the switch as an interrupt for when we turn pin change interrupts on
- PCMSK = (1 << SWITCH_PIN);
- - // Set PWM pin to output
- + // Set FET and PWM pin to output
- #ifdef ALT_MODES
- - DDRB = (1 << PWM_PIN) | (1 << ALT_PWM_PIN);
- + DDRB = (1 << FET_PIN) | (1 << PWM_PIN) | (1 << ALT_PWM_PIN);
- #else
- - DDRB = (1 << PWM_PIN);
- + DDRB = (1 << FET_PIN) | (1 << PWM_PIN);
- #endif
- // Set timer to do PWM for correct output pin and set prescaler timing
- @@ -396,14 +397,6 @@ int main(void)
- #endif
- ACSR |= (1<<7); //AC off
- - // Determine if we are going L-H, or H-L based on Star 3
- - if ((PINB & (1 << STAR3_PIN)) == 0) {
- - // High to Low
- - low_to_high = 0;
- - } else {
- - low_to_high = 1;
- - }
- -
- // Enable sleep mode set to Power Down that will be triggered by the sleep_mode() command.
- set_sleep_mode(SLEEP_MODE_PWR_DOWN);
- sleep_until_switch_press();
- @@ -427,7 +420,18 @@ int main(void)
- #endif
- }
- }
- - PWM_LVL = modes[mode_idx];
- + if (modes[mode_idx] == TURBO)
- + {
- + // Turn on FET instead of main PWM.
- + PORTB |= (1 << FET_PIN);
- + PWM_LVL = 0;
- + }
- + else
- + {
- + // Turn off FET, use requested main PWM.
- + PORTB &= ~(1 << FET_PIN);
- + PWM_LVL = modes[mode_idx];
- + }
- #ifdef ALT_MODES
- ALT_PWM_LVL = alt_modes[mode_idx];
- #endif
- @@ -441,4 +445,4 @@ int main(void)
- }
- return 0; // Standard Return Code
- -}
- \ No newline at end of file
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement