Beispiel #1
0
void flash_led_once()
{

    //LED_PORT &= ~_BV(LED);
    turn_led_on();
    delay_thsec();
    //LED_PORT |= _BV(LED);
    turn_led_off();
    delay_esec();
}
Beispiel #2
0
void flash_led_long()
{
    //LED_PORT |= _BV(LED);
    turn_led_off();
    delay_sec();
    //LED_PORT &= ~_BV(LED);
    turn_led_on();
    delay_sec();
    //LED_PORT |= _BV(LED);
    turn_led_off();
    delay_sec();
}
Beispiel #3
0
int main() {
  DDRA = ALL_INPUT;
  PORTA = ALL_GND_PULL_OFF;
  DDRB = ALL_INPUT;
  PORTB = ALL_POS_PULL_ON;

  // set prescaler to 1024
  TCCR1B = _BV(CS12) | _BV(CS10);
  
  while (1) {
    for (uint8_t n = 0; n < NUM_ANIMATIONS; n++) {
      uint8_t next_animation = 0;
      uint16_t frame_count = 0;
      memcpy_P(&frame_count, &ANIMATIONS[n]->num_frames, sizeof(frame_count));
      while (1) {
        for (uint16_t f = 0; f < frame_count; f++) {
          anim_frame cur_frame;
          memcpy_P(&cur_frame, &ANIMATIONS[n]->frames[f], sizeof(cur_frame));
          for (TCNT1 = 0; TCNT1 < cur_frame.dur; /*nothing*/) {
            for (uint8_t i = 0; i < 27; i++) {
              uint8_t tmp_port = ALL_GND_PULL_OFF, tmp_ddr = ALL_INPUT;
              if (cur_frame.leds[i]) {
                turn_led_on(&tmp_ddr, &tmp_port, i);
              }
              DDRA = tmp_ddr;
              PORTA = tmp_port;
            }
            DDRA = ALL_INPUT;
            PORTA = ALL_POS_PULL_ON;
            DDRB = ALL_INPUT;
            PORTB = ALL_POS_PULL_ON;

            // TODO: make sure the button comes up
            // to make this less time-dependant
            if (bit_is_clear(MODE_PIN, MODE_BIT)) {
              next_animation = 1;
              _delay_ms(1000);
              break;
            }
          }
          if (next_animation) break;
        }
        if (next_animation) break;
      }
    }
  }
  DDRA = ALL_INPUT;
  PORTA = ALL_GND_PULL_OFF;
  return 0;
}
Beispiel #4
0
static void shine_leds(uint16_t dur, uint8_t cur_vals[]) {
  for (TCNT1 = 0; TCNT1 < dur; /*nothing*/) {
    for (uint8_t t = 0; t < BIT_SCHED_LEN; t++) {
      for (uint8_t i = 0; i < NUM_LEDS; i++) {
        uint8_t tmp_port = ALL_GND_PULL_OFF, tmp_ddr = ALL_INPUT;
        if (lookup_on_off(cur_vals[i], t)) {
          turn_led_on(&tmp_ddr, &tmp_port, i);
        }
        DDRA = tmp_ddr;
        PORTA = tmp_port;
      }
      DDRA = ALL_INPUT;
      PORTA = ALL_POS_PULL_ON;
      DDRB = ALL_INPUT;
      PORTB = ALL_POS_PULL_ON;

      if (go_to_sleep) {
        _delay_ms(2000);

        cli();
        set_sleep_mode(SLEEP_MODE_PWR_DOWN);
        sleep_enable();
        // don't wake up via mode button
        GIMSK &=  ~_BV(PCIE0);
        sei();

        sleep_cpu();

        sleep_disable();
        GIMSK |=  _BV(PCIE0);
        _delay_ms(1000);
        go_to_sleep = 0;
      }

      if (next_animation || TCNT1 > dur) break;
    }

    if (next_animation) break;
  }
}