| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

ButtonUtility

Page history last edited by William 8 years, 2 months ago

int checkButton() {

  int result = 0;

 

  ppState = digitalRead(play_pauseButton);

  if(ppState == 1 && ppStateLast == 0)

    result = PLAY_PAUSE;

  ppStateLast = ppState;

 

  nState = digitalRead(nextButton);

  if(nState == 1 && nStateLast == 0)

    result = NEXT;

  nStateLast = nState;

 

  preState = digitalRead(previousButton);

  if(preState == 1 && preStateLast == 0)

    previous(result);

  preStateLast = preState;

 

  vUState = digitalRead(volumeUpButton);

  if(vUState == 1 && vUStateLast == 0)

    result = VOL_UP;

  vUStateLast = vUState;

 

  vDState = digitalRead(volumeDownButton);

  if(vDState == 1 && vDStateLast == 0)

    result = VOL_DOWN;

  vDStateLast = vDState;

 

  return result;

}    

 

//Changes the state to idle or the prev_state when play/pause pressed 

void changePlay(){

  if(current_state != IDLE){

    prev_state = current_state;

    current_state = IDLE;

    Mp3.cancel_playback();

  }

 

  else if(current_state == IDLE){

    current_state = prev_state;

  }

}

 

//Skips to the next song when button pushed

void skipAhead(){

  sd_file.close();

  Mp3.clear_buffer();

  FindSong();

  Serial.println("Got here");

  sd_file_open();

}

 

//Skips to the beginning of the current song when pushed

void skipBehind(){

  Mp3.cancel_playback();

  Serial.println("Back got here");

  Mp3.clear_buffer();

  sd_file.seekSet(10);

}

 

 

//Changes to vol. Note that the user cannot change the volume below the min

//or above the max. Also sets the vol in EEPROM every time a user chages the

//volume. This allows the player to find know the last volume when it starts up

#define MAX_VOL 254

#define MIN_VOL 0

 

void changeVol(int buttonCmd){

  if(buttonCmd == VOL_UP){

    if(mp3_vol < MAX_VOL) mp3_vol += 5;

    else mp3_vol = MAX_VOL;

    EEPROM.write(1023, mp3_vol);

    Mp3.volume(mp3_vol);

  } 

 

  if(buttonCmd == VOL_DOWN){

    if(mp3_vol > MIN_VOL) mp3_vol -= 5;

    else mp3_vol = MIN_VOL;

    EEPROM.write(1023, mp3_vol);

    Mp3.volume(mp3_vol);

  } 

 

Comments (0)

You don't have permission to comment on this page.