Search code examples
shellaudioarduinosd-cardarduino-yun

arduino yun with usb sound card geting number of files


i have project in which i have to play a number of sound files at random, at the push of a button iam using an arduino yun. so far i can play the sounds from the sd card, however i want the random number to generate depending on the number of files in the sd card.i need help in reading the number of files through the command shell from the sketch

cd /mnt/sda1 
ls | wc - l

when i this in the terminal i get the answer 4 and thats exactly the answer i need. i want to run this in the script, so far i have this however it doesnt seem to work

d.runShellCommand("ls | wc -l | cd /mnt/sda1");
result = d.parseInt();
Serial.println(result);

can anyone help me in fixing this

thank you


Solution

  • Your shell command has a few errors in it. Rather than pipe to a cd command, you can simply specify the directory when running ls. for example:

    ls | wc -l | cd ~/Documents/
    

    outputs nothing. However,

    ls ~/Documents/ | wc -l
    

    Outputs the number of files and folders in my documents folder. So this command should work:

    d.runShellCommand("ls /mnt/sda1| wc -l");