예제 #1
0
/* Plays tone in background endlessly. Use noTone() to stop it.
 *  @param pin    The pin to play on. Only pins which support PWM will
 *      work.
 *  @param frequency  The frequency to play in Hz. Use 0 to disable tone.
 *      Should be between 125 Hz and 32 kHz.
 *  @param volume Volume between 0 and 10 (inclusive). Volume of 0 will
 *      disable tone.
 */               
void tone(int pin, int frequency) {
  if (frequency == 0) {
    noTone(pin);
    return;
  }

  // set the top (period)
  unsigned long top = 93750 / frequency;
  top = constrain(top, 0, 255);
  
  if (top == 0) {
    noTone(pin);
    return;
  }

  setupTone(pin);
    
  // Select programmable PWM CLK source to 93 kHz
  _cy_set_register(0x29, 0x03);
  _cy_set_register(0x2A, top);

  // set duty cycle (pulse width)
  unsigned int duty = top / 2; // Calculate the duty cycle (volume).
  _cy_set_register(0x2B, duty);
}
예제 #2
0
void PlayMelody(int pin, char *notes, boolean (*af)())
{
  char nc, w ;
  int n, t, l ;

  pinMode(pin, OUTPUT) ;
  _notEpointeR = notes ;

  while ((nc = *_notEpointeR++) != '\0') {
    if ((af != NULL) && (af() == false)) return ;
    t = l = 0 ;
    if ((nc >= 'a') && (nc <= 'z')) nc -= 32 ;
#ifdef DEBUG
    Serial.print(_tempO, DEC) ;
    Serial.print(", ") ;
    Serial.print(_octavE, DEC) ;
    Serial.print(", ") ;
    Serial.print(nc, BYTE) ;
    Serial.print(", ") ;
#endif
    w = _wherEnotEchaR(nc) ;
    if (w < 7) {
      nc = _notEindeX[w] ;
      w = _wherEnotEchaR(*_notEpointeR) ;
      if ((w == 7) || (w == 8)) {
        _notEpointeR++ ;
        nc++ ;
      }
      if ((w == 9) || (w == 10)) {
        _notEpointeR++ ;
        nc-- ;
      }
      t = _notEratE[nc] * (55 << (_octavE - 1)) ;
      w = 99 ;
      tone(pin, t) ;
    }
    n = _tOnumbeR() ;
    if ((t > 0) || (w == 11) || (w == 12)) {
      if (w == 11) noTone(pin) ;
      if (n == 0) n = _lengtH ;
      l = 12000 / _tempO * 40 / n ;
      if (*_notEpointeR == '.') {
        _notEpointeR++ ;
        l *= 1.5 ;
      }
    }
    if ((w == 13) && (_octavE < 8)) _octavE++ ;
    if ((w == 14) && (_octavE > 1)) _octavE-- ;
    if ((w == 15) && (n >= 1) && (n <= 8)) _octavE = n ;
    if ((w == 16) && (n >= 1) && (n <= 512)) _tempO = n ;
    if ((w == 17) && (n >= 1) && (n <= 128)) _lengtH = n ;
#ifdef DEBUG
    Serial.print(t, DEC) ;
    Serial.print(", ") ;
    Serial.println(l, DEC) ;
#endif
    if (l > 0) delay(l) ;
    noTone(pin) ;
  }
}
예제 #3
0
void Atm_player::action( int id ) {
  switch ( id ) {
    case ENT_FINISH:
      onfinish.push();
      return;
    case ENT_IDLE:
      if ( pin >= 0 ) noTone( pin );
      counter_repeat.set( repeatCount );
      return;
    case ENT_START:
      step = 0;
      counter_repeat.decrement();
      return;
    case ENT_SOUND:
      onnote[1].push( pattern[step * 3] * pitchFactor, 1 );
      if ( pin >= 0 ) tone( pin, pattern[step * 3] * pitchFactor );
      timer.set( pattern[step * 3 + 1] * speedFactor );
      return;
    case ENT_QUIET:
      onnote[0].push( pattern[step * 3], 0 );
      if ( pin >= 0 ) noTone( pin );
      timer.set( pattern[step * 3 + 2] * speedFactor );
      return;
    case ENT_NEXT:
      step++;
      return;
    case ENT_REPEAT:
      return;
  }
}
예제 #4
0
파일: Music.cpp 프로젝트: PotiBox/PotiBox
void Music::cycle(unsigned long currentTime) {
  _isPlaying = false;

  // kill our playing if we are past our times
  if (isEmptyMelody()) {
    return;
  } else if (_notePosition > (NOTES_COUNT - 1)) {
    setMelody(MELODY_NONE);
    return;
  }

  _isPlaying = true;

  unsigned long toneElapsedTime = currentTime - _toneTimer;

  if (!_firstNotePlayed) {
    noTone(_speakerPin);
    tone(_speakerPin, _currentNote, _currentDuration);

    _toneTimer = currentTime;
    _firstNotePlayed = true;
  } else if (toneElapsedTime > (_currentDuration * 1.3)) {
    noTone(_speakerPin);

    _toneTimer = currentTime;
    _notePosition++;
    setCurrentNoteAndDuration(_notePosition);

    if (isEndNote(_notePosition)) {
      return;
    }

    tone(_speakerPin, _currentNote, _currentDuration);
  }
}
예제 #5
0
파일: redbot.cpp 프로젝트: TIDAL-Lab/tern2
void beep() {
    tone(buzzerPin, 1000);   // Play a 1kHz tone on the pin number held in
    delay(125);   // Wait for 125ms. 
    noTone(buzzerPin);   // Stop playing the tone.

    tone(buzzerPin, 2000);  // Play a 2kHz tone on the buzzer pin
    delay(500);   // delay for 1000 ms (1 second)
    noTone(buzzerPin);       // Stop playing the tone.
}
예제 #6
0
void AccessControl::successTone() {
    successLight();
    
    tone(_buzzerPin, NOTE_C4);
    delay(250);
    noTone(_buzzerPin);
    tone(_buzzerPin, NOTE_A4);
    delay(250);
    noTone(_buzzerPin);
}
예제 #7
0
파일: syc-002.cpp 프로젝트: dome2048/syc
void beep3()
{  
	tone(sirenPin, 4000);
	delay(200);
	noTone(sirenPin);
	delay(50);
	tone(sirenPin, 4650);
	delay(500);
	noTone(sirenPin);
}
예제 #8
0
파일: syc-002.cpp 프로젝트: dome2048/syc
void beep4()
{  
	tone(sirenPin, 4125);
	delay(100);
	noTone(sirenPin);
	delay(50);
	tone(sirenPin, 4000);
	delay(500);
	noTone(sirenPin);
}
예제 #9
0
파일: syc-002.cpp 프로젝트: dome2048/syc
void beep1()
{  
	tone(sirenPin, 4000);
	delay(50);
	noTone(sirenPin);
	delay(50);
	tone(sirenPin, 4000);
	delay(50);
	noTone(sirenPin);
}
예제 #10
0
//Feedback Tones
void AccessControl::failureTone() {
    failureLight();
    
    tone(_buzzerPin, NOTE_A5);
    delay(250);
    noTone(_buzzerPin);
    tone(_buzzerPin, NOTE_C4);
    delay(250);
    noTone(_buzzerPin);
    
}
예제 #11
0
// Sound the buzzer at frequency freq (Hz) for time t (millisceconds)
void BrainBoard::beep(uint16_t freq, uint16_t t)
{
	if( freq ){
		tone(BUZZER, freq);
		delay(t);
		if( t ){ //set t=0 to leave it buzzing forever
			noTone(BUZZER);
		}
	}else{
		noTone(BUZZER);
	}
}
예제 #12
0
파일: main.c 프로젝트: ohwada/PIC16F84A
void main(void) {
    /* Initialize I/O and Peripherals for application */
    TRISA = 0x02;   // RA1 input, others outpot
    TRISB = 0x00;   // PortB all output
    PORTA = 0x00;   // PortA all low
    PORTB = 0x00;   // PortB all low

    // OPTION_REG
    OPTION_REG = OPTION_REG_VALUE ;
    // Timer 0
    tmr0_value = 114;   // RA
    t333ms_max = 133;
    TMR0 = tmr0_value ;
    // TMR0 Overflow Interrupt Enable bit = Enables
    INTCONbits.TMR0IE =1; 
    // Global Interrupt Enable bit = Enables
    INTCONbits.GIE = 1;

    // start game
    is_debug = !PORTAbits.RA1;    // button
    is_digit[0] = false;
    is_digit[1] = false;
    is_digit[2] = false;
    digit[0] = 2;
    digit[1] = 1;
    digit[2] = 0;
    tone( DO5, 50, 50 );
    status = ST_WAIT ;

    // loop if push button
    while( status == ST_WAIT ) {
        upDigit(true);
        __delay_ms(500);
    }

    // endless loop
    while(1) {
        if ( status == ST_BUTTON_1 ) {
            noTone( 10 );
            status = ST_PLAY_2 ;
        } else if ( status == ST_BUTTON_2 ) {
            noTone( 10 );
            status = ST_PLAY_3 ;
        } else if ( status == ST_BUTTON_3 ) {
            endGame();
        } else if (( status == ST_PLAY_1 )||( status == ST_PLAY_2 )||( status == ST_PLAY_3 )) {
            tone( FA, 10, 3 );
            tone( SO, 15, 3 );
            tone( FA, 10, 3 );
            tone( RA, 15, 3 );
        }
    }
}
void TonePlayer::step(Task* task) {
  TonePlayer* tp = (TonePlayer*)task;
  
  // -- play a small silence after each tone
  if(tp->_playing) {
    tp->_playing = false;
    noTone(tp->_outPin);
    tp->setPeriodMs(tp->_baseLength / 20);
    return;
  }

  // -- finished
  if(tp->_pos >= tp->_tones.length()) {
    SoftTimer.remove(tp);
    noTone(tp->_outPin);
    return;
  }

  // -- calculate length
  char cLength = tp->_tones[tp->_pos+1];
  tp->setPeriodMs((unsigned long)(cLength-'0') * tp->_baseLength);

  // -- calculate tone
  char cPitch = tp->_tones[tp->_pos];
  if(cPitch == '_') {
    // -- add silence
    noTone(tp->_outPin);
  } else {
    float val = A440;
    int tune = (int)(cPitch-'j'); // -- 'j' character means A note
    if(tune < -9) {
      tune += 6; // -- Skip characters between character capital 'Z' and 'a'.
    }
    if(tune > 0) {
      while(tune != 0) {
        val *= trot;
        --tune;
      }
    } else {
      while(tune != 0) {
        val /= trot;
        ++tune;
      }
    }

    // -- play tone
    tone(tp->_outPin, val);
  }
  
  tp->_playing = true;
  tp->_pos += 2;
}
예제 #14
0
파일: syc-002.cpp 프로젝트: dome2048/syc
void beep2()
{  
	digitalWrite(ledR, LOW);
	tone(sirenPin, 4000);
	delay(50);
	noTone(sirenPin);
	delay(50);
	tone(sirenPin, 4000);
	delay(1000);
	noTone(sirenPin);
	delay(500);
	digitalWrite(ledR, HIGH);
}
예제 #15
0
void loop()
{
    // Calling tone twice in a row on different pins
    Log(L"Calling tone twice in a row on different pins\n");
    Log(L"Tone On: %d\n", frequency);
    tone(tonePin, frequency);
    Sleep(500);
    Log(L"Tone2 On: %d\n", frequency);
    tone(tonePinTwo, frequency);
    Sleep(500);

    // Calling tone twice in a row on the same pin
    Log(L"Calling tone twice in a row on the same pin\n");
    Log(L"Tone On: %d\n", frequency);
    tone(tonePin, frequency);
    Sleep(500);
    frequency = frequency + 50;
    Log(L"Tone On: %d\n", frequency);
    tone(tonePin, frequency);
    Sleep(500);
    frequency = frequency + 50;

    // Calling tone and no tone one after another
    Log(L"Calling tone and no tone one after another\n");
    Log(L"Tone On: %d\n", frequency);
    tone(tonePin, frequency);
    Sleep(500);
    Log(L"Tone Off\n");
    noTone(tonePin);
    frequency = frequency + 50;

    // Calling noTone twice in a row
    Log(L"noTone twice in a row\n");
    Sleep(500);
    Log(L"Tone Off\n");
    noTone(tonePin);
    frequency = frequency + 50;

    // Calling tone with a duration and noTone before it's timer
    Log(L"Calling tone with a duration and noTone before it's timer\n");
    tone(tonePin, 100, 2000);
    noTone(tonePin);

    // Calling tone with a duration and letting the callback hit
    Log(L"Calling tone with a duration and letting the callback hit\n");
    tone(tonePin, 100, 2000);
    Sleep(3000);
}
예제 #16
0
void desligarAlarme() {
  //Desligando o led
  digitalWrite(pinLed, LOW);
   
  //Desligando o buzzer
  noTone(pinBuzzer);
}
예제 #17
0
void boot_tone (int pin)
{
    // notes in the melody:
    int melody[] = {
        NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4
    };

    // note durations: 4 = quarter note, 8 = eighth note, etc.:
    int noteDurations[] = {
        4, 8, 8, 4,4,4,4,4
    };

    // iterate over the notes of the melody:
    for (int thisNote = 0; thisNote < 8; thisNote++)
    {
        // to calculate the note duration, take one second
        // divided by the note type.
        //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
        int noteDuration = 1000 / noteDurations[thisNote];
        tone (pin, melody[thisNote], noteDuration);

        // to distinguish the notes, set a minimum time between them.
        // the note's duration + 30% seems to work well:
        int pauseBetweenNotes = noteDuration * 1.30;
        delay (pauseBetweenNotes);
        // stop the tone playing:
        noTone (pin);
    }
}
	void update() {
		btn.update();
		led.update();

		if (btn.isLongClicked()) {
			speakerOn = !speakerOn;
			if (speakerOn) {
				tone(speakerPin, toneState.getValue());
			} else {
				noTone(speakerPin);
			}
		} else if (btn.isClicked()) {
			rotor.setState(rotor.getState() == &toneState ? &ledState : &toneState);
		}

		if (toneState.hasValueChanged()) {
			long newTone = toneState.getValue();
			if (speakerOn) {
				tone(speakerPin, newTone);
			}
			float tps = rotor.tps.getTPS();
			Serial.print("Tone ");
			Serial.print(newTone);
			Serial.print(" ");
			Serial.println(tps);
		}

		if (ledState.hasValueChanged()) {
			int newLed = (int) ledState.getValue();
			led.setState(newLed);
			Serial.print("Led ");
			Serial.println(newLed);
		}
	}
예제 #19
0
	void Tone(u8 pin, u16 freq, u16 duration)
	{
		PWM_setFrequency(freq);
		PWM_setPercentDutyCycle(pin, 50);
		Delayms(duration);						// length of sound in ms 
		noTone(pin);
	}
void Buzzer::turnOff() {
  if ( ! _hardwareSetupComplete ) {
    _setupHardware();
  }
  noTone(_pin);
  _stateIsOn = false;
}
예제 #21
0
/*public */TSTError TSTTone::setup(TSTMorikawa* morikawa)
{
    TSTError error(TSTERROR_OK);
    
#if defined(OPTION_BUILD_MEMORYLOG)
    TSTMorikawa::saveMemoryLog();
#endif
#if defined(TARGET_INVADER_EM1) || defined(TARGET_INVADER_FM1)
    if (morikawa != NULL) {
        if (_morikawa == NULL) {
            _morikawa = morikawa;
            _bpm = DEFAULT_BPM;
            _wpm = DEFAULT_WPM;
            noTone(PIN_TONE_WAVE);
        }
        else {
            error = TSTERROR_INVALID_STATE;
        }
    }
    else {
        error = TSTERROR_INVALID_PARAM;
    }
#else
    error = TSTERROR_NO_SUPPORT;
#endif
    return error;
}
uint8_t ToneActuator::update() {
  uint32_t curr_time = millis();
  if ((curr_time - _last_cmd) > _shutoff_ms) {
    noTone(_pin);
  }
  return status_level;
}
예제 #23
0
void AccessControl::ackTone() {
    ackLight();
  
    tone(_buzzerPin, NOTE_A4);
    delay(200);
    noTone(_buzzerPin);
}
예제 #24
0
void RtttlPlayer::pause() {
    if (_isPlaying) {
        noTone(_buzzerPin);
        _isPlaying = false;
        setState((PState) &RtttlPlayer::PAUSED);
    }
}
예제 #25
0
State RtttlPlayer::PLAYING_NOTE() {
    if (isTimeout(_noteDuration)) {
        noTone(_buzzerPin);
        _noteDuration *= 0.2; // pause between notes
        setState((PState) &RtttlPlayer::PAUSE_BETWEEN_NOTES);
    }
}
예제 #26
0
파일: redbot.cpp 프로젝트: TIDAL-Lab/tern2
void setup()
{
  pinMode(buttonPin, INPUT_PULLUP); // configures the button as an INPUT
  pinMode(buzzerPin, OUTPUT);  // configures the buzzerPin as an OUTPUT
  tone(buzzerPin, 2000); delay(300); noTone(buzzerPin);
  delay(100);
}
void GeneratorWithPressureSensor::loop() {
	tps.update();
	led.update();

	tps.smooth(analogRead(pressurePin), &pressure, 4);
	tps.smooth(analogRead(cellTemperaturePin), &cellTemperature, 4);
	tps.smooth(analogRead(mosfetTemperaturePin), &mosfetTemperature, 4);
	tps.smooth(analogRead(ambientTemperaturePin), &ambientTemperature, 4);
	tempCurrent = analogRead(currentPin);
	if (tempCurrent > currentMinThreshold) {
		currentTPS.update();
		currentTPS.smooth(tempCurrent, &current, 4);
	}

	processReader();
	if (maxPressure < pressure)
		maxPressure = pressure;
	if (maxCurrent < current)
		maxCurrent = current;
	if (checkThresholdsExceeded()) {
		// turn off
		noTone(mosfetPin);
		led.playBlink(BLINK_FAST, 0);
		if (isPlaying) {
			isPlaying = false;
			showStatus(true);
		}
	}
}
예제 #28
0
/**
 * @brief Enables or disables the piezo buzzer using a certain frequency
 * @param[in] frequency Frequency (Hz) of tone to generate, or zero to disable
 * @see KG_PIN_PIEZO
 */
void feedback_set_piezo_tone(uint16_t frequency) {
    if (frequency == 0) {
        noTone(KG_PIN_PIEZO);
    } else {
        tone(KG_PIN_PIEZO, frequency);
    }
}
예제 #29
0
void playNote(int note_frequency, int note_duration) {

  if (note_frequency > 0) {
    int pause_between_notes = 9;
    tone( BUZZER_PIN , note_frequency);
    delay(note_duration - pause_between_notes); // duration in millis
    noTone(BUZZER_PIN);
    delay(pause_between_notes);

    
//    analogWriteFrequency(BUZZER_PIN, note_frequency);
//    analogWrite(BUZZER_PIN, 512);
//    delay(note_duration - pause_between_notes); // duration in millis
//    analogWrite(BUZZER_PIN, 0);
//    delay(pause_between_notes);
    
  }
  else {
    delay(note_duration);
  }

  analogWriteFrequency(MOTOR_LF_PWM_PIN, 46875);
  analogWriteFrequency(MOTOR_RF_PWM_PIN, 46875);
  analogWriteFrequency(MOTOR_LB_PWM_PIN, 46875);
  analogWriteFrequency(MOTOR_RB_PWM_PIN, 46875);
}
예제 #30
0
void SoundSystem::init() {
  noTone(speaker_pin);
  ticks_per_beat = TICKS_PER_BEAT_MAX;
  tick_counter = 0;
  note_counter = 0;
  note_index = 0;
}