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);
		}
	}
Пример #2
0
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);
  }
}
  void loop() {
  // read the sensor:
  int sensorone = digitalRead(2);
  int sensortwo = digitalRead(3);
  int sensorthree = digitalRead(4);
  int sensorfour = digitalRead(5);
  int sensorfive = digitalRead(6);

  if (sensorone == HIGH){
  // play the pitch:
  tone(9, NOTE_A4, 20);
  delay(1); // delay in between reads for stability
  }
  if (sensortwo == HIGH) {
  // play the pitch:
  tone(9, NOTE_G4, 20);
  delay(1); 
  }
  
  if (sensorthree == HIGH) {
  tone(9, NOTE_E4, 20);
  delay(1);
  }
  
  if (sensorfour == HIGH) {
  tone(9, NOTE_D4, 20);
  delay(1);
  }
 
  if (sensorfive == HIGH) { 
  tone(9, NOTE_C4, 20);
  delay(1);
  } 
}  
Пример #4
0
static void doIndicateStep(uint8_t step)
{

  switch(sequence[step])
  {
    case INDICATE_RED:
    {
      tone(SPEAKER_PIN, NOTE_A4);
      digitalWrite(RED_LED_PIN, HIGH);
      break;
    }

    case INDICATE_BLUE:
    {
      tone(SPEAKER_PIN, NOTE_G4);
      digitalWrite(BLUE_LED_PIN, HIGH);
      break;
    }

    case INDICATE_YELLOW:
    {
      tone(SPEAKER_PIN, NOTE_C4);
      digitalWrite(YELLOW_LED_PIN, HIGH);
      break;
    }

    case INDICATE_GREEN:
    {
      tone(SPEAKER_PIN, NOTE_G5);
      digitalWrite(GREEN_LED_PIN, HIGH);
      break;
    }
  }
}
Пример #5
0
int test_spkr(String input)
{
  tone(BUZZER_PIN, 600, 150);
  delay(150);
  tone(BUZZER_PIN, 900, 150);

  return 0;
};
void buzzer::registered()
{
	tone(pin,4000);
	delay(300);
	tone(pin,2000);
	delay(300);
	tone(pin,4000,200);
	
}
Пример #7
0
IR_rangeZone_detection::IR_rangeZone_detection()
{
  tone(speakerPin, 2000,500);
  delay(1000);
  tone(speakerPin, 2000, 500);
  
  pinMode(irRecPinLeft, INPUT);  pinMode(irLEDPinLeft, OUTPUT);   // IR LED & Receiver
  pinMode(irRecPinRight, INPUT);  pinMode(irLEDPinRight, OUTPUT);
}
Пример #8
0
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.
}
Пример #9
0
void AccessControl::successTone() {
    successLight();
    
    tone(_buzzerPin, NOTE_C4);
    delay(250);
    noTone(_buzzerPin);
    tone(_buzzerPin, NOTE_A4);
    delay(250);
    noTone(_buzzerPin);
}
Пример #10
0
void beep4()
{  
	tone(sirenPin, 4125);
	delay(100);
	noTone(sirenPin);
	delay(50);
	tone(sirenPin, 4000);
	delay(500);
	noTone(sirenPin);
}
Пример #11
0
void beep1()
{  
	tone(sirenPin, 4000);
	delay(50);
	noTone(sirenPin);
	delay(50);
	tone(sirenPin, 4000);
	delay(50);
	noTone(sirenPin);
}
Пример #12
0
mrb_value mrb_arduino_tone(mrb_state *mrb, mrb_value self){
  mrb_int pin, frequency, duration;
  int n = mrb_get_args(mrb, "ii|i", &pin, &frequency, &duration);
  if (n == 2){
    tone(pin, frequency);
  }else if(n == 3){
    tone(pin, frequency, duration);
  }
  return mrb_nil_value();
}
Пример #13
0
void beep3()
{  
	tone(sirenPin, 4000);
	delay(200);
	noTone(sirenPin);
	delay(50);
	tone(sirenPin, 4650);
	delay(500);
	noTone(sirenPin);
}
Пример #14
0
gboolean packet_received(GtkWidget *leak) {
	int i;
	char *buffer;
	struct tcphdr *tcp_hdr;
	struct udphdr *udp_hdr;
	struct ip *ip_hdr;
	int linkoff=14;


	buffer = (u_char *)pcap_next(pcap_d,&h);
	packetcount++;

	ip_hdr = (struct ip *)(buffer + linkoff);
	
	if (ip_hdr->ip_p == IPPROTO_TCP) {
		tcp_hdr=(struct tcphdr*)(((char*)ip_hdr)+(4*ip_hdr->ip_hl));

		switch ((tcp_hdr->th_flags)) {	

			case TH_ACK:		
				update_port(leak, ntohs(tcp_hdr->th_dport), 0, 255, 0);
				if (sound_onoff) {
					tone(ntohs(tcp_hdr->th_dport), 4000, 60);
				}
				break;

			case TH_SYN:
				update_port(leak, ntohs(tcp_hdr->th_dport), 255, 255, 0); if (sound_onoff) {
					tone(ntohs(tcp_hdr->th_dport), 4000, 60);
				}
				break;

			case TH_FIN:
				update_port(leak, ntohs(tcp_hdr->th_dport), 255, 0, 0);
				if (sound_onoff) {
					tone(ntohs(tcp_hdr->th_dport), 4000, 60);
				}
				break;

			default:
				break;

		}	
  	} else if (ip_hdr->ip_p == IPPROTO_UDP) {
		udp_hdr=(struct udphdr*)(((char*)ip_hdr)+(4*ip_hdr->ip_hl));

		update_port(leak, ntohs(udp_hdr->uh_dport), 0, 0, 255);
		if (sound_onoff) {
			tone(ntohs(udp_hdr->uh_dport), 4000, 60);
		}
	}
	
	
	return TRUE;
}
Пример #15
0
//Feedback Tones
void AccessControl::failureTone() {
    failureLight();
    
    tone(_buzzerPin, NOTE_A5);
    delay(250);
    noTone(_buzzerPin);
    tone(_buzzerPin, NOTE_C4);
    delay(250);
    noTone(_buzzerPin);
    
}
Пример #16
0
void waitStart()
{
    tone(E5, 50);
    while((getTelemeterDist(TELEMETER_FL) >= WAIT_START_DISTANCE) &&
            (getTelemeterDist(TELEMETER_FR) >= WAIT_START_DISTANCE));
    tone(E5, 50);
    HAL_Delay(20);
    tone(E5, 50);
    while((getTelemeterDist(TELEMETER_FL) <= WAIT_START_DISTANCE) ||
            (getTelemeterDist(TELEMETER_FR) <= WAIT_START_DISTANCE));
    toneItMode(D6, 200);
}
Пример #17
0
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 );
        }
    }
}
Пример #18
0
void loop() {
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
	long duration, inches, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
	pinMode(pingPin, OUTPUT);
	digitalWrite(pingPin, LOW);
	delayMicroseconds(2);
	digitalWrite(pingPin, HIGH);
	delayMicroseconds(10);
	digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
	pinMode(inPin, INPUT);
	duration = pulseIn(inPin, HIGH);

// convert the time into a distance
	inches = microsecondsToInches(duration);
	cm = microsecondsToCentimeters(duration);

	Serial.println(cm, DEC);

	if (cm < 3) {
		// play the note corresponding to this sensor:
		tone(8, notes[4], 30);
	}

	if ((cm >= 3) && (cm <= 9)) {
		// play the note corresponding to this sensor:
		tone(8, notes[0], 30);
	}

	if ((cm >= 10) && (cm <= 19)) {
		// play the note corresponding to this sensor:
		tone(8, notes[1], 30);
	}
	if ((cm >= 20) && (cm <= 29)) {
		// play the note corresponding to this sensor:
		tone(8, notes[2], 30);
	}

	if ((cm >= 30) && (cm <= 49)) {
		// play the note corresponding to this sensor:
		tone(8, notes[3], 30);
	}

	delay(100);
}
Пример #19
0
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);
}
Пример #20
0
static void bootDelay()
{
	const int soundFreq = 100;
	const int bootTime = 7500;
	const int bootPartTime = 500;

	tone(pinPiezo, toneAccepted, soundFreq);
	for (uint8_t i = 0; i < bootTime / bootPartTime; i++)
	{
		delay(bootPartTime);
		wdt_reset();
	}
	tone(pinPiezo, toneAccepted, soundFreq);
}
uint8_t ToneActuator::set_cmd(bool cmd) {
  _last_cmd = millis();
  bool actual_command = _is_active_low ? !cmd : cmd;
  if (actual_command) {
    if (_tone_duration > 0){
      tone(_pin, _tone_frequency, _tone_duration);
    }else{
      tone(_pin, _tone_frequency);
    }
  }
  else {
    noTone(_pin);
  }
  return status_level;
}
Пример #22
0
Call builtin_setBeat(Env parent_env, Args args) {
    Number n = (Number)args_get(args, 0);
    Closure k = (Closure)args_get(args, 1);
    tone(PIEZO_PIN, (int)n->value);
    delay(60000 / tempo);
    return create_call(k, create_args(0));
}
Пример #23
0
static void
playtone(int pitch, int val, int sustain)
/* play tone of proper duration for current rhythm signature */
{
    int	sound, silence, snum = 1, sdenom = 1;

    /* this weirdness avoids floating-point arithmetic */
    for (; sustain; sustain--)
    {
	snum *= NUM_MULT;
	sdenom *= DENOM_MULT;
    }

    if (pitch == -1)
	rest(whole * snum / (val * sdenom));
    else
    {
	sound = (whole * snum) / (val * sdenom)
		- (whole * (FILLTIME - fill)) / (val * FILLTIME);
	silence = whole * (FILLTIME-fill) * snum / (FILLTIME * val * sdenom);

#ifdef SPKRDEBUG
	printf("playtone: pitch %d for %d ticks, rest for %d ticks\n",
	    pitch, sound, silence);
#endif /* SPKRDEBUG */

	tone(pitchtab[pitch], sound);
	if (fill != LEGATO)
	    rest(silence);
    }
}
Пример #24
0
// the loop function runs over and over again forever
void loop() {
  ButtonMgr::update();

  mainSM.run();
  // Serial.println("And ON");
  // digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  // delay(5000);              // wait for a second
  // Serial.println("And OFF");
  // digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  // delay(1000);              // wait for a second

  // digitalWrite(RED_LED_PIN, !digitalRead(RED_BUTTON_PIN));
  // digitalWrite(BLUE_LED_PIN, !digitalRead(BLUE_BUTTON_PIN));
  // digitalWrite(YELLOW_LED_PIN, !digitalRead(YELLOW_BUTTON_PIN));
  // digitalWrite(GREEN_LED_PIN, !digitalRead(GREEN_BUTTON_PIN));
  //
  //

  if(    ButtonMgr::isPressed(RED_BUTTON_IDX)
      || ButtonMgr::isReleased(RED_BUTTON_IDX) )
  {
    tone(SPEAKER_PIN, NOTE_A4, 250);
  }

}
Пример #25
0
int main(void)
{
	unsigned constrained = 0, shutOffBuzzer = 0;
	
	//Set GPIO Pins
	if(!shutOffBuzzer)
		DDRB|=0b00100000; //PIN 13 output to buzzer
	
	DDRB|=0b00001000;

	sei();
		
	setupADC();
	setupPWM();
	startPWM();
	
	count=0;
    InitTimer0();
	StartTimer0();
	
	while(1)
    {	
		if(state)
			pwm_val = remap(adc_val,100,900);
		else
		{
		//0-255 steps for tone strength
			constrained = remap(adc_val,619,890);			
		//Output tone
			tone(constrained);
		}	
    }
}
Пример #26
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) ;
  }
}
Пример #27
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);
    }
}
Пример #28
0
/* 
 * Play tone of proper duration for current rhythm signature 
 */
static void
playtone(int pitch, int value, int sustain)
{
	register int sound, silence, snum = 1, sdenom = 1;

	/* this weirdness avoids floating-point arithmetic */
	for (; sustain; sustain--) {
		/* See the BUGS section in the man page for discussion */
		snum *= NUM_MULT;
		sdenom *= DENOM_MULT;
	}

	if (value == 0 || sdenom == 0)
		return;

	if (pitch == -1)
		rest(whole * snum / (value * sdenom));
	else {
		sound = (whole * snum) / (value * sdenom)
			- (whole * (FILLTIME - fill)) / (value * FILLTIME);
		silence = whole * (FILLTIME-fill) * snum / (FILLTIME * value * sdenom);

#ifdef DEBUG
		(void) printf("playtone: pitch %d for %d ticks, rest for %d ticks\n",
			pitch, sound, silence);
#endif /* DEBUG */

		tone(pitchtab[pitch], sound);
		if (fill != LEGATO)
			rest(silence);
	}
}
Пример #29
0
void BattleAnimation::Draw() {
	if (!screen) {
		// Initialization failed
		return;
	}

	if (frame >= (int) animation->frames.size())
		return;

	const RPG::AnimationFrame& anim_frame = animation->frames[frame];

	std::vector<RPG::AnimationCellData>::const_iterator it;
	for (it = anim_frame.cells.begin(); it != anim_frame.cells.end(); ++it) {
		const RPG::AnimationCellData& cell = *it;
		int sx = cell.cell_id % 5;
		int sy = cell.cell_id / 5;
		int size = large ? 128 : 96;
		Rect src_rect(sx * size, sy * size, size, size);
		Tone tone(cell.tone_red, cell.tone_green, cell.tone_blue, cell.tone_gray);
		int opacity = 255 * (100 - cell.transparency) / 100;
		double zoom = cell.zoom / 100.0;
		DisplayUi->GetDisplaySurface()->EffectsBlit(
			x + cell.x, y + cell.y,
			size / 2, size / 2,
			*screen, src_rect, 
			opacity, tone,
			zoom, zoom);
	}
}
Пример #30
0
void AccessControl::ackTone() {
    ackLight();
  
    tone(_buzzerPin, NOTE_A4);
    delay(200);
    noTone(_buzzerPin);
}