Published

Music Player with LinkIt One

A simple music player built with LinkIt One to demonstrate high school kids the power of Arduino-compatible boards.

IntermediateFull instructions provided1,144
Music Player with LinkIt One

Things used in this project

Hardware components

LinkIt ONE
MediaTek Labs LinkIt ONE
×1
8 Channel Touch Capacitive Switch
×1
Male to Female Dupont Wires
×1
iM60 Portable Speaker from iHome
×1
Kingston 8gb Micro SD Card
×1

Story

Read more

Code

AudioPlayer.ino

C/C++
#include <LAudio.h>
#include <LSD.h>

int Pad1 = 0;
int Pad2 = 1;
int Pad3 = 2;
int Pad4 = 3;
int Pad5 = 4;
int Pad6 = 5;
int Pad7 = 6;
int Pad8 = 7;

int CheckPads()
{
  int readPad1 = digitalRead(Pad1);
  if(readPad1 == HIGH) return 1;
  int readPad2 = digitalRead(Pad2);
  if(readPad2 == HIGH) return 2;
  int readPad3 = digitalRead(Pad3);
  if(readPad3 == HIGH) return 3;
  int readPad4 = digitalRead(Pad4);
  if(readPad4 == HIGH) return 4;
  int readPad5 = digitalRead(Pad5);
  if(readPad5 == HIGH) return 5;
  int readPad6 = digitalRead(Pad6);
  if(readPad6 == HIGH) return 6;  
  int readPad7 = digitalRead(Pad7);
  if(readPad7 == HIGH) return 7;
  int readPad8 = digitalRead(Pad8);
  if(readPad8 == HIGH) return 8;
  return 0;
}

void PlayPad(int padId)
{
  switch(padId)
  {
    case 1: 
     LAudio.setVolume(3);
      LAudio.playFile( storageSD,(char*)"001.mp3");
       Serial.println("Play Pad 1");
      break;
    case 2: 
      LAudio.setVolume(3);
      LAudio.playFile( storageSD,(char*)"002.mp3");
      Serial.println("Play Pad 2");
      break;
    case 3: 
      LAudio.setVolume(3);
      LAudio.playFile( storageSD,(char*)"003.mp3");
      Serial.println("Play Pad 3");
      break;
    case 4: 
      LAudio.setVolume(3);
      LAudio.playFile( storageSD,(char*)"004.mp3");
      Serial.println("Play Pad 4");
      break;
    case 5: 
      LAudio.setVolume(3);
      LAudio.playFile( storageSD,(char*)"005.mp3");
      Serial.println("Play Pad 5");
      break;
    case 6: 
      LAudio.setVolume(3);
      LAudio.playFile( storageSD,(char*)"006.mp3");
      Serial.println("Play Pad 5");
      break;
    case 7: 
      LAudio.setVolume(3);
      LAudio.playFile( storageSD,(char*)"007.mp3");
      Serial.println("Play Pad 5");
      break;
    case 8: 
      LAudio.setVolume(3);
      LAudio.playFile( storageSD,(char*)"BetterNotCall.mp3");
      Serial.println("Play Pad 5");
      break;
  }
}

void setup()
{
  LAudio.begin();
  LSD.begin(); // Init SD card

  pinMode(Pad1, INPUT);
  pinMode(Pad2, INPUT);
  pinMode(Pad3, INPUT);
  pinMode(Pad4, INPUT);
  pinMode(Pad5, INPUT);
  pinMode(Pad6, INPUT);
  pinMode(Pad7, INPUT);
  pinMode(Pad8, INPUT);

  Serial.begin(115200);
  Serial.println("Running");

  pinMode(8, OUTPUT);
  LAudio.setVolume(3);
  
}
bool hasRun = false;
void loop()
{
 //  AudioStatus status = LAudio.getStatus();
 //  if(status == 1 || status == 5 || !hasRun)
  // {
  //   hasRun = true;
     int pad =0;
     while(pad == 0)
     {
       pad = CheckPads();
       Serial.println("waiting...");
     }
     PlayPad(pad);
  // }
   delay(500);
}

Credits

CodeWarriorMalo

Comments

Add projectSign up / Login