Exemplo n.º 1
0
static void pin_write_handler(ble_lbs_t * p_lbs, uint8_t * pin_state)
{  
    
    // Sets motor values for every motor.

    twi_set_motor(pin_state);

    // Sets the color for every RGB-LED.

    uint8_t web_color_data = read_byte(pin_state, 5);
    set_rgb_color(web_color_data);

    // Shoots IR-signal.
    if (read_bit(pin_state, 1, 0))
    {
        ir_shooting(pin_state);
        playNote(536);
        nrf_delay_ms(50);
        playNote(536);
    }
    
    // Turns laser on when game session is active
    if(read_bit(pin_state, 1, 1))
    {
       nrf_gpio_pin_set(LASER_TRANSISTOR);
    }
    else
       nrf_gpio_pin_clear(LASER_TRANSISTOR);

    write_car_id(pin_state[19]);
    unique_car_ID = pin_state[19];
}
Exemplo n.º 2
0
//---------------------------------------------------------
//   processEvent
//    All events from the sequencer go here
//---------------------------------------------------------
bool ISynth::processEvent(const MusECore::MidiPlayEvent& ev)
      {
      switch(ev.type()) {
            case MusECore::ME_CONTROLLER:
                setController(ev.channel(), ev.dataA(), ev.dataB());
                //return true;  // ??
                break;            
            case MusECore::ME_NOTEON:
                  return playNote(ev.channel(), ev.dataA(), ev.dataB());
            case MusECore::ME_NOTEOFF:
                  return playNote(ev.channel(), ev.dataA(), 0);
            case MusECore::ME_SYSEX:
                  return sysex(ev.len(), ev.data());
            case MusECore::ME_PITCHBEND:
                setController(ev.channel(), MusECore::CTRL_PITCH, ev.dataA());
                break;
            // Synths are not allowed to receive ME_PROGRAM, CTRL_HBANK, or CTRL_LBANK alone anymore - only CTRL_PROGRAM.
            //case MusECore::ME_PROGRAM:
            //    setController(ev.channel(), MusECore::CTRL_PROGRAM, ev.dataA());
            //    break;   
            default:
                break;
            }
      return false;
      }
Exemplo n.º 3
0
void automaticPlay(tMusicNote musicNote) {
	
	uint16_t note = musicNote.note;
	long duration = musicNote.duration;
	playNote(note);
	sleep(duration);
	playNote(0);
}
Exemplo n.º 4
0
void soundBuzzer()
{
	// using wavelengths from
	// http://www.phy.mtu.edu/~suits/notefreqs.html

	playNote( 2100 ) ;
	playNote( 1990 ) ;
	playNote( 1870 ) ;
	playNote( 1770 ) ;
	playNote( 1670 ) ;
}
Exemplo n.º 5
0
int main(void)
{ 
    uint32_t err_code;

    //Initialize GPIO
    nrf_gpiote_init();
    pin_output_init(); 
    
    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);



    // Initialize PWM
    pwm_init(); 

    // Initialize
    timers_init();
    
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();

    //Starts advertising
    advertising_timer_init();
    advertising_start();

    //Initialize shields
    twi_motordriver_init();
    twi_rfid_init();

    // Initialize the IR lib. Must be done after initializing the SoftDevice
    ir_lib_init(IR_OUTPUT_PIN);
    err_code = ir_ppi_init();
    APP_ERROR_CHECK(err_code);

    //Feedback, notifying the user that the DK is ready
    set_rgb_color(0);
    playNote(1607);
    nrf_delay_ms(30);
    playNote(1516);
    nrf_delay_ms(30);
    playNote(1431);

     // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
Exemplo n.º 6
0
void Soundy::playABC(String abc) {

  //abc.toLowerCase(); // legacy
  
  Serial.write("L="+L);
  
  for (int n = 0; n < abc.length(); n++) {
    char note = abc.charAt(n);    

    if (!isNote(String(note))) continue;
    Serial.write(note);

    int duration = 1;    
    if (n < abc.length()-1) {
      String next = String(abc.charAt(n+1));
      if (next.toInt() > 0) {
        duration = next.toInt();        
        n++;
      }
    }
    Serial.write(duration);    
        
    if (note == ' ') {
      delay ( duration * L);
    } else {
      playNote(String(note), duration * L);
    }
    delay( L / 2);    
  }
}
Exemplo n.º 7
0
void searchFinishMelody() { //


  int tempo = 300; // tempo in beats per minute

  // set duration of a whole note
  int millis_per_whole_note = 4.0 * 60.0 * 1000.0 / (float)tempo;

  int note_list[] = {
    NOTE_G3, NOTE_C4, NOTE_E4, NOTE_G4, NOTE_C5, NOTE_E5, NOTE_G5, NOTE_E5,
    NOTE_GS3, NOTE_C4, NOTE_DS4, NOTE_GS4, NOTE_C5, NOTE_DS5, NOTE_GS5, NOTE_DS5,
    NOTE_AS3, NOTE_D4, NOTE_F4, NOTE_AS4, NOTE_D5, NOTE_F5, NOTE_AS5, NOTE_AS5, NOTE_AS5, NOTE_AS5, NOTE_C6
  };

  float note_duration[] = {
    0.16666, 0.16666, 0.16666, 0.16666, 0.16666, 0.16666, 0.5, 0.5,
    0.16666, 0.16666, 0.16666, 0.16666, 0.16666, 0.16666, 0.5, 0.5,
    0.16666, 0.16666, 0.16666, 0.16666, 0.16666, 0.16666, 0.5, 0.16666, 0.16666, 0.16666, 1
  };

  // send notes to playing function
  for (int this_note = 0; this_note < 27 ; this_note++) {
    playNote( note_list[this_note], (int)((float)note_duration[this_note] * (float)millis_per_whole_note));
  }
}
Exemplo n.º 8
0
void SoundGenCoCo3::play(int resnum) {
	int i = cocoFrequencies[0]; // Silence warning

	i = i + 1;

#if 0
	int i = 0;
	CoCoNote note;

	do {
		note.read(_chn[i].ptr);

		if (note.freq != 0xff) {
			playNote(0, cocoFrequencies[note.freq], note.volume);

			uint32 start_time = _vm->_system->getMillis();

			while (_vm->_system->getMillis() < start_time + note.duration) {
				_vm->_system->updateScreen();

				_vm->_system->delayMillis(10);
			}
		}
	} while (note.freq != 0xff);
#endif
}
Exemplo n.º 9
0
/* if CMD < 0x80, then the other 7 bits and the next byte are a 15-bit big-endian number of msec to wait */
void ArduboyTunes::step()
{
  byte command, opcode, chan;
  unsigned duration;

  while (1) {
    command = pgm_read_byte(score_cursor++);
    opcode = command & 0xf0;
    chan = command & 0x0f;
    if (opcode == TUNE_OP_STOPNOTE) { /* stop note */
      stopNote(chan);
    }
    else if (opcode == TUNE_OP_PLAYNOTE) { /* play note */
      playNote(chan, pgm_read_byte(score_cursor++));
    }
    else if (opcode == TUNE_OP_RESTART) { /* restart score */
      score_cursor = score_start;
    }
    else if (opcode == TUNE_OP_STOP) { /* stop score */
      tune_playing = false;
      break;
    }
    else if (opcode < 0x80) { /* wait count in msec. */
      duration = ((unsigned)command << 8) | (pgm_read_byte(score_cursor++));
      wait_toggle_count = ((unsigned long) wait_timer_frequency2 * duration + 500) / 1000;
      if (wait_toggle_count == 0) wait_toggle_count = 1;
      break;
    }
  }
}
Exemplo n.º 10
0
void Sound::stopNote()
{
  // stop the tone playing:
  noNewTone(_pin);
  // play the next one if there is one
  playNote();
}
Exemplo n.º 11
0
void ArduboyTunes::initChannel(byte pin)
{
  byte timer_num;

  // we are all out of timers
  if (_tune_num_chans == AVAILABLE_TIMERS)
    return;

  timer_num = pgm_read_byte(tune_pin_to_timer_PGM + _tune_num_chans);
  _tune_pins[_tune_num_chans] = pin;
  _tune_num_chans++;
  pinMode(pin, OUTPUT);
  switch (timer_num) {
    case 1: // 16 bit timer
      TCCR1A = 0;
      TCCR1B = 0;
      bitWrite(TCCR1B, WGM12, 1);
      bitWrite(TCCR1B, CS10, 1);
      _tunes_timer1_pin_port = portOutputRegister(digitalPinToPort(pin));
      _tunes_timer1_pin_mask = digitalPinToBitMask(pin);
      break;
    case 3: // 16 bit timer
      TCCR3A = 0;
      TCCR3B = 0;
      bitWrite(TCCR3B, WGM32, 1);
      bitWrite(TCCR3B, CS30, 1);
      _tunes_timer3_pin_port = portOutputRegister(digitalPinToPort(pin));
      _tunes_timer3_pin_mask = digitalPinToBitMask(pin);
      playNote(0, 60);  /* start and stop channel 0 (timer 3) on middle C so wait/delay works */
      stopNote(0);
      break;
  }
}
Exemplo n.º 12
0
bool Mess::processEvent(const MidiPlayEvent& ev)
      {
      switch(ev.type()) {
            case ME_NOTEON:
                  return playNote(ev.channel(), ev.dataA(), ev.dataB());
            case ME_NOTEOFF:
                  return playNote(ev.channel(), ev.dataA(), 0);
            case ME_SYSEX:
	            return sysex(ev.len(), ev.data());
            case ME_CONTROLLER:
                  return setController(ev.channel(), ev.dataA(), ev.dataB());
            case ME_PITCHBEND:       // Tim.
                  return setController(ev.channel(), CTRL_PITCH, ev.dataA());
            }
      return false;
      }
Exemplo n.º 13
0
void playString(const char *str) {
  int len = strlen(str);
  
  int note = 0;
  int octave = 3;
  float duration = 0.45f;

  for(int i = 0; i < len; i++) {
    char c = tolower(str[i]);

    if(c >= 'a' && c <= 'g') {
      // it's a new note, play previous one
      if(note != 0) 
	playNote(note + octave * 12, duration);
      
      // start a new one
      note = charToNote(c);
    }
    else if(c == '-') {
      note--;
    }
    else if(c == '+') {
      note++;
    }
    else if(c >= '0' && c <= '9') {
      // change duration
      float t = (c - '0');
      duration = tempo * t / 4.0f;
    }
    else if(c == 'o' && i < len - 1) {
      if(note != 0)
	playNote(note + octave * 12, duration);
      note = 0;

      i++;
      char val = tolower(str[i]);
      if(val >= '0' && val <= '9') {
	octave = val - '0';
      }
    }
  }

  // play last note
  if(note != 0)
    playNote(note + octave * 12, duration);
}
Exemplo n.º 14
0
int *bubbleSort(int list[], int length, float lengthOfBeat)
{
	int i, j, temp;
	int eachNote = 0;
	int *noteList;

	noteList = (int*) malloc(sizeof(int));

	while(!eachNote) {
		for (j = 0; j < length - 1; j++) {
			for (i = 0; i < length - j - 1; i++) {
				if (list[i] > list[i + 1]) {
					temp = list[i];
					list[i] = list[i + 1];
					list[i + 1] = temp;
					
					noteList = realloc(noteList, (eachNote + 1) * sizeof(int));
					
					noteList[eachNote] = list[i] * SCALING_FACTOR;
					noteList[eachNote + 1] = list[i + 1] * SCALING_FACTOR;

					eachNote = eachNote + 2;
	
					playNote(list[i] * SCALING_FACTOR, lengthOfBeat);
					playNote(list[i + 1] * SCALING_FACTOR, lengthOfBeat);
				}
			}
		}

		break;
	}

	int note;

	for (note = 0; note < eachNote; note++) {
		printf("%d\n", noteList[note]);
	}

	dumpToFile(noteList, eachNote * sizeof(int), lengthOfBeat, "sounds/bubbleSort.wav");

	int *listptr;

	listptr = &list[0];

	return listptr;
}
void playSong() {
  for(int i = 0; i<length;++i) {
  if(notes[i]==' ') {delay(beats[i]*tempo);//beats[i]
  } else {
    playNote(notes[i],beats[i]*tempo);//
 }
 }
}
Exemplo n.º 16
0
int main(void) {
  // -------- Inits --------- //
  initTimer();
  // ------ Event loop ------ //
  while (1) {
                                                    /* Play some notes */
    playNote(C2, 200);
    playNote(E2, 200);
    playNote(G2, 200);
    playNote(C3, 400);

    _delay_ms(1000);
    _delay_ms(1000);
    _delay_ms(1000);

  }                                                  /* End event loop */
  return (0);                            /* This line is never reached */
}
void loop() {
  for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], beats[i] * tempo);
    }
    // pause between notes
    delay(tempo / 2); 
  }
}
Exemplo n.º 18
0
void InternetButton::playSong(String song){
    char inputStr[200];
    song.toCharArray(inputStr,200);
    
    Serial.println(inputStr);
    
    char *note = strtok(inputStr,",");
    char *duration = strtok(NULL,",");
    playNote(note,atoi(duration));
    
    while(duration != NULL){
        note = strtok(NULL,",");
        Serial.println(note);
        duration = strtok(NULL,", \n");
        Serial.println(duration);
        //if(atoi(duration) <= 0){
        //    break;
        //}
        playNote(note,atoi(duration));
    }
}
Exemplo n.º 19
0
int singToMe(String args)
{
  for (int i = 0; i < args.length(); i++) {
    char oneNote = args.charAt(i);
    //I can't figure out what space is being translated into (it's not space or +) so z = rest
    if (oneNote == 'z') {
      delay(tempo);
    } else {
      playNote(oneNote, tempo);
    }
  }
}
Exemplo n.º 20
0
void Sound::playNotes(int length, int melody[], int noteDurations[]) 
{
  this->_melody = melody;
  this->_noteDurations = noteDurations;
  //this->_size = sizeof(melody) / sizeof(int);

  
  this->_length = length;
  this->enable();
  _current_note = 0;
  playNote();
}
Exemplo n.º 21
0
void sonido_perder()
{
for (int i = 0; i < length2; i++) 
       { if (notes1[i] == ' ') 
           { 
             delay(beats2[i] * tempo); // rest 
           } 
         else 
           { 
             playNote(notes2[i], beats2[i] * tempo); 
           } // pause between notes delay(tempo); 
        }
} 
Exemplo n.º 22
0
void sonido_inicio()
{
for (int i = 0; i < length3; i++) 
       { if (notes3[i] == ' ') 
           { 
             delay(beats3[i] * tempo); // rest 
           } 
         else 
           { 
             playNote(notes3[i], beats3[i] * tempo); 
           } // pause between notes delay(tempo); 
        }
} 
Exemplo n.º 23
0
// Function to decode IR signals and message to web if the car is hit
void ir_in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
      static uint8_t decoded = 0;
      static uint8_t offset = 0;
      static uint32_t prev = 0;

      if(offset >= 8)
          offset = 0;

      uint32_t usec = nrf_drv_timer_capture(&ir_timer, NRF_TIMER_CC_CHANNEL0); 
      if(offset) 
          SEGGER_RTT_printf(0, "%d\r\n", usec - prev);
      
      if((usec - prev) > 2000)
      {
          decoded += (1 << (offset - 1));
      }
      
      if(offset == 7) 
      {
          SEGGER_RTT_printf(0, "\r\n\n%d\n\r\n", decoded);
          new_hit_value();
          if(decoded != unique_car_ID && decoded >= 1 && decoded <= 16)
          {
              ble_lbs_on_button_change(&m_lbs, hit_counter, 0);            
          
              playNote(1516);
              nrf_delay_ms(50);
              playNote(1607);
          }

          decoded = 0;
      }
            

      prev = usec;
      offset++;
}
Exemplo n.º 24
0
static void pin_event_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action){
    //if(pin == IR_RECEIVER_PIN_1 || pin == IR_RECEIVER_PIN_2 || pin == IR_RECEIVER_PIN_3){
      
     /*hit_counter = new_hit_value();
      playNote(1516);
      nrf_delay_ms(50);
      playNote(1607);*/

     /* if(pin == IR_RECEIVER_PIN_1) {          
          ir_in_pin_handler(pin, action);
           //ble_lbs_on_button_change(&m_lbs, hit_counter, 0);
      }
      else if(pin == IR_RECEIVER_PIN_2)
            ble_lbs_on_button_change(&m_lbs, hit_counter, 1);
      else if(pin == IR_RECEIVER_PIN_3)
            ble_lbs_on_button_change(&m_lbs, hit_counter, 2);
    }*/

    if(pin == RFID_INTERRUPT_PIN) {
        ble_lbs_on_button_change(&m_lbs, rfid_counter, 4);

        if(rfid_counter % 20 == 0){
            playNote(1072);
            set_rgb_color(2);
            nrf_delay_ms(10);
            playNote(1012);
            set_rgb_color(1);
            nrf_delay_ms(10);
            playNote(955);
            set_rgb_color(2);
            nrf_delay_ms(10);
            playNote(901); 
            set_rgb_color(0);
        }
        rfid_counter = rfid_read_event_handler();
    }
}
Exemplo n.º 25
0
/*public */TSTError TSTTone::playNotePGM(NoteSequence const PROGMEM* sequence, int length)
{
    TSTError error(TSTERROR_OK);
    
#if defined(OPTION_BUILD_MEMORYLOG)
    TSTMorikawa::saveMemoryLog();
#endif
    if (sequence != NULL) {
        error = playNote(NULL, sequence, length);
    }
    else {
        error = TSTERROR_INVALID_PARAM;
    }
    return error;
}
Exemplo n.º 26
0
void pianoPlay(void) {

	uint16_t note;
	while(1) {

		note = getNote();

		if (note == 1) {
			break;
		}
		playNote(note);
		sleep(56); /* minimum sleep time */
	}

}
Exemplo n.º 27
0
//---------------------------------------------------------
//   processEvent
//    All events from the sequencer go here
//---------------------------------------------------------
bool ISynth::processEvent(const MusECore::MidiPlayEvent& ev)
      {
      switch(ev.type()) {
            case MusECore::ME_CONTROLLER:
                setController(ev.channel(), ev.dataA(), ev.dataB());
                //return true;  // ??
                break;            
            case MusECore::ME_NOTEON:
                  return playNote(ev.channel(), ev.dataA(), ev.dataB());
            case MusECore::ME_NOTEOFF:
                  return playNote(ev.channel(), ev.dataA(), 0);
            case MusECore::ME_SYSEX:
                  return sysex(ev.len(), ev.data());
            case MusECore::ME_PITCHBEND:
                setController(ev.channel(), MusECore::CTRL_PITCH, ev.dataA());
                break;            
            case MusECore::ME_PROGRAM:
                setController(ev.channel(), MusECore::CTRL_PROGRAM, ev.dataA());
                break;   
            default:
                break;
            }
      return false;
      }
Exemplo n.º 28
0
int main(int argc, char** argv)
{
    int i;
    speakerMode = 0;
    int speakerModeIndex = 0;
    for (i = 0; i < argc; i++)
    {
	if (eq(argv[i], "--speaker"))
	{
	    speakerMode = 1;
	    speakerModeIndex = i;
	}
    }
    
    msPer = 200;
    if (argc > (1+speakerMode))
    {
	if (eq(argv[1], "--help"))
	{
	    printf("Usage: beepi <length per note in ms>\n");
	    return 0;
	}

	if ((!speakerMode) || speakerModeIndex == 2) 
	    msPer = atoi(argv[1]);
	else if (speakerModeIndex == 1)
	    msPer = atoi(argv[2]);
	
    }
    
    
    
    
    FILE* fp;
    fp = fopen("pi.txt", "r");
    int sz;
    fseek(fp, 0L, SEEK_END);
    sz = ftell(fp);
    fseek(fp, 0L, SEEK_SET);
    char* buffer = malloc(100000);
    fread(buffer, sz, 1, fp);
    fclose(fp);

    for (i = 0; i < strlen(buffer); i++)
	if (playNote(buffer[i]))
	    return 0;
    
}
Exemplo n.º 29
0
void Player::playSong(Song inSong)
  {

    for (int i = 0; i < inSong.length; i++)
    {
      if (inSong.notes[i] == ' ') {
        delay(inSong.beats[i] * inSong.tempo); // rest
      }
      else {
        playNote(inSong.notes[i], inSong.beats[i] * inSong.tempo);
      }

      // pause between notes
      delay(inSong.tempo / 2);
    }
  }
Exemplo n.º 30
0
void Menu::turn()
{
  gUserInterface.waitForHand();
  playNote(2000, 200);
  delay(1000);

  enc_left_front_write(0);
  enc_right_front_write(0);
  enc_left_back_write(0);
  enc_right_back_write(0);
  Orientation::getInstance()->resetHeading();

  motion_forward(180, 0, 0);
  motion_rotate(180);
  motion_forward(180, 0, 0);
  motion_hold(100);
}