Home Forums Sparkfun MP3 Shield Library Support Forum Bakelite Phone and MP3 shield

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3236
    Anonymous
    Inactive

    Can someone please help me, I can’t work out why the below code isnt working.

    I have installed all the libraries, and labelled MP3s using 8.3 file naming system.

    I am so grateful of any help.

     

    Cheers,

    Annie

     

    Heres the code:

     

     

    // libraries

    #include <SPI.h>

    #include <SdFat.h>

    #include <SdFatUtil.h>

    #include <SFEMP3Shield.h>

     

    SdFat sd;

    SFEMP3Shield MP3player;

     

     

    int dial = 14;

     

    int track1 = 0;

    int track2 = 1;

    int track3 = 2;

    int track4 = 3;

    int track5 = 4;

    int track6 = 5;

    int track7 = 6;

    int track8 = 7;

    int track7 = 8;

    int track8 = 9;

     

    int needToPrint = 0;

    int count;

    int lastState = LOW;

    int trueState = LOW;

    long lastStateChangeTime = 0;

     

    // constants

     

    int dialHasFinishedRotatingAfterMs = 100;

    int debounceDelay = 10;

     

     

     

    void setup() {

    Serial.begin(115200);

     

     

    pinMode(dial, INPUT);

     

     

    if(!sd.begin(9, SPI_HALF_SPEED)) sd.initErrorHalt();

    if (!sd.chdir(“/”)) sd.errorHalt(“sd.chdir”);

     

    MP3player.begin();

    MP3player.setVolume(10,10);

    }

     

     

    void loop()

    {

    int reading = digitalRead(dial);

    int reading2 = count;

     

    if ((millis() – lastStateChangeTime) > dialHasFinishedRotatingAfterMs) {

    // the dial isn’t being dialed, or has just finished being dialed.

    if (needToPrint) {

    // if it’s only just finished being dialed, we need to send the number down the serial

    // line and reset the count. We mod the count by 10 because ‘0’ will send 10 pulses.

    Serial.println(count);

    needToPrint = 0;

    count = 0;

    if (reading2 == track2) {

    Serial.println (“happy”);

    MP3player.playTrack(1);

    }

    }

     

    }

     

    if (reading != lastState) {

    lastStateChangeTime = millis();

    }

    if ((millis() – lastStateChangeTime) > debounceDelay) {

    // debounce – this happens once it’s stablized

    if (reading != trueState) {

    // this means that the switch has either just gone from closed->open or vice versa.

    trueState = reading;

    if (trueState == HIGH) {

    // increment the count of pulses if it’s gone high.

    count++;

    needToPrint = 1; // we’ll need to print this number (once the dial has finished rotating)

     

    }

    }

    }

    lastState = reading;

    }

     

     

     

     

     

     

     

     

     

     

    #3240
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.