User Tools

Site Tools


courses:intro.prototyping.spring.2012.may15

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
courses:intro.prototyping.spring.2012.may15 [2012/05/15 05:35]
130.239.235.97
courses:intro.prototyping.spring.2012.may15 [2012/05/16 19:51] (current)
camille
Line 1: Line 1:
 +=== Rogue rMP3 audio shield for Arduino ==
 +
 +As you may remember we have previously used audio in prototyping by using a glitchy external mp3-player called Vmusic2. The limitations and frustrating unreliability have sent me and Camille to look for an alternative and the best one on the market right now is the rMp3 audio-shield that Camille found and summarized [[Arduino:​rMP3 Audio Shield|here]].
 +
 +For handy accessibility the most common commands are listed [[http://​www.roguerobotics.com/​wikidocs/​code/​library/​arduino/​roguemp3#​methods|here]].
 +
 +{{:​arduino:​roguemp3_for_1.0_camille.zip|rMP3-library}}
 +
 +
 +== Button example ==
 +<code java>
 +#include <​RogueMP3.h>​
 +#include <​SoftwareSerial.h>​
 + // make sure this file exists in the root folder on the SD card
 +#define sound1 "/​hhm.wav"​
 +
 +//Extra serial port for commands
 +SoftwareSerial rmp3_serial(6,​ 7);
 +//Instance of shield object for control
 +RogueMP3 rmp3(rmp3_serial);​
 +
 +//Variable to keep track of button
 +int button1State = 0;
 +
 +void setup()
 +{
 +  pinMode(2, INPUT);
 +  ​
 +  Serial.begin(9600);​
 +  rmp3_serial.begin(9600);​
 +  rmp3.sync();​
 + 
 +  Serial.println(rmp3.version());​
 + 
 +}
 + 
 +void loop()
 +{
 +  button1State = digitalRead(2);​
 +
 +  if(button1State == HIGH)
 +  {
 +    delay(200);
 +    rmp3.playfile(sound1);​
 +    Serial.println(button1State);​
 +    button1State = LOW;
 +   ​} ​
 +}
 +</​code>​
 +
 +== Analog example ==
 +<code java>
 +#include <​RogueMP3.h>​
 +#include <​SoftwareSerial.h>​
 +// make sure this file exists in the root folder on the SD card
 +#define sound1 "/​YODA.wav"​
 +
 +//Extra serial port for commands
 +SoftwareSerial rmp3_serial(6,​ 7);
 +//Instance of shield object for control
 +RogueMP3 rmp3(rmp3_serial);​
 +
 +//Variables for sensor value and player status
 +int sensorVal;
 +char playing;
 +
 +void setup()
 +{
 +  Serial.begin(9600);​
 +  rmp3_serial.begin(9600);​
 +
 +  rmp3.sync();​
 +
 +  Serial.println(rmp3.version()); ​
 +}
 +
 +void loop()
 +{
 +  //Reading sensor
 +  sensorVal = analogRead(A0);​
 +  if(sensorVal > 300)
 +  {
 +    //Getting player status
 +    playing = rmp3.getplaybackstatus(); ​  
 +    if(playing != '​P'​)
 +    {
 +      //Play file
 +      rmp3.playfile(sound1);​
 +      Serial.println("​Playing"​);​
 +    }
 +  }
 +}
 +
 +</​code>​
  
courses/intro.prototyping.spring.2012.may15.txt · Last modified: 2012/05/16 19:51 by camille