예제 #1
0
void LED::set(led_state_t state) {
  if (_lastState == state)
     return;
  _lastState = state;
  if(_pin == -1) {
      Serial.printf("LED - change to state %d\n", state);
      return;
  }
  switch(state) {
    case LED_OFF:
      _ticker.detach();
      _off();
      break;
    case LED_ON:
      _ticker.detach();
      _on();
      break;
    case LED_FLASH:
    case LED_IDLE:
    case LED_PENDING:
    case LED_FAST:
      _ticker.attach_ms(100, &flipPin, this); // no need to detach - code will disarm and re-use existing timer.
      break;
    case LED_SLOW:
      _ticker.attach_ms(500, &flipPin,  this); // no need to detach - code will disarm and re-use existing timer.
      break;
    case LED_ERROR:
    case NEVERSET: // include this here - though it should enver happen. 50 hz flash
    default:
      _ticker.attach_ms(20, &flipPin, this); // no need to detach - code will disarm and re-use existing timer.
      break;
  }
}
예제 #2
0
/* ======================================================= */
void setCE(uint8_t value)
{
	if (value) {
		_on(SPI_CE, PORTB);
	} else {
		_off(SPI_CE, PORTB);
	}
}
예제 #3
0
/* ======================================================= */
void setCSN(uint8_t value)
{
	if (value) {
		_on(SPI_CSN, PORTB);
	} else {
		_off(SPI_CSN, PORTB);
	}
}
예제 #4
0
void fixZeroValueOCR() {
	if (OCR0A == 0) {
		TCCR0A &= ~( _BV(COM0A1) | _BV(COM0A0) );
		_off(PD6, PORTD);
	} else {
		TCCR0A |= (1<<COM0A1) | (0<<COM0A0);
	}

	if (OCR0B == 0) {
		TCCR0A &= ~( _BV(COM0B1) | _BV(COM0B0) );
		_off(PD5, PORTD);
	} else {
		TCCR0A |= (1<<COM0B1) | (0<<COM0B0);
	}

	if (OCR2B == 0) {
		TCCR2A &= ~( _BV(COM2B1) | _BV(COM2B0) );
		_off(PD3, PORTD);
	} else {
		TCCR2A |= (1<<COM2B1) | (0<<COM2B0);
	}
}
예제 #5
0
/********************************************************************************
Main
********************************************************************************/
int main(void) {
    // initialize code
	usart_init();

	// initialize input port for ir receiver
	_in(DDE4,   DDRE);
	_on(PE4,    PORTE);

	// initialize input port interrupt
	_on(ISC40,  EICRB);
	_off(ISC41, EICRB);
	_on(INT4,   EIMSK);

	// initialize 16 bit timer 1
	TCCR1B = (0<<CS12)|(1<<CS11)|(1<<CS10);
	_on(TOIE1, TIMSK);

    // enable interrupts
    sei();

    printf("INIT AFTER RESET");

    // main loop
    while (true) {
    	if (send_data_flag && ir_data_count > 0) {

    		printf("START PACKET");

    		for (uint16_t i = 0; i < ir_data_count; i++) {
    			usart_putchar(ir_data[i]);
    		}

    		printf("END PACKET");

    		ir_data_count = 0;
    		send_data_flag = 0;
    	}
    }
}