Example #1
0
// frequency (in hertz) and duration (in milliseconds).
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) {
  _pin = esp8266_pinToGpio[_pin];
  int8_t _index;

  _index = toneBegin(_pin);

  if (_index >= 0) {
    // Set the pinMode as OUTPUT
    pinMode(_pin, OUTPUT);

    // Calculate the toggle count
    if (duration > 0) {
      toggle_counts[_index] = 2 * frequency * duration / 1000;
    } else {
      toggle_counts[_index] = -1;
    }

    // set up the interrupt frequency
    switch (tone_timers[_index]) {
      case 0:
        // Not currently supported
        break;

      case 1:
        timer1_disable();
        timer1_isr_init();
        timer1_attachInterrupt(t1IntHandler);
        timer1_enable(TIM_DIV1, TIM_EDGE, TIM_LOOP);
        timer1_write((clockCyclesPerMicrosecond() * 500000) / frequency);
        break;
    }
  }
}
Example #2
0
static void initTimer() {
  timer1_disable();
  timer1_isr_init();
  timer1_attachInterrupt(timer1Interrupt);
  lastCycleCount = GetCycleCount();
  timer1_enable(TIM_DIV1, TIM_EDGE, TIM_SINGLE);
  timerRunning = true;
}
Example #3
0
void rcOutputsInit(){
	int i;
	for(i=0; i<RC_OUTNUM; i++){
		pinMode(rc_out_pins[i], OUTPUT);
		digitalWrite(rc_out_pins[i], LOW);
	}
	//updates the screen every second
	timer1_disable();
	timer1_attachInterrupt(onRcTimer);
	timer1_enable(TIM_DIV16, TIM_EDGE, TIM_SINGLE);
	timer1_write(5000000);//1 second
}
Example #4
0
static void deinitTimer() {
  timer1_attachInterrupt(NULL);
  timer1_disable();
  timer1_isr_init();
  timerRunning = false;
}
Example #5
0
void pwm_start_timer(){
	timer1_disable();
	timer1_attachInterrupt(pwm_timer_isr);
	timer1_enable(TIM_DIV1, TIM_EDGE, TIM_SINGLE);
	timer1_write(1);
}