Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Finding out the battery life of arduino? on: February 05, 2014, 03:17:57 pm
My question is pretty simple. I just want to know if there is a simple way in the arduino code to find out what the battery power is at and then print it into the serial? Like, find out what the battery life is currently, and then say it's at like 70% power, print 70% to the serial?
2  Using Arduino / Programming Questions / Can you run methods in arduino code? on: January 23, 2014, 04:50:34 am
Hi. We are writing some code for a servo, and we're not very familiar with the arduino coding style. What we want to do is have three different blocks of code, and then run different blocks depending on the instruction. So, my question is simply can we write say 3 different methods, and then say like, if instruction char is equal to 1, run method one, if equal to to char2, run method 2 etc? If it is possible, what would be the syntax for writing it? I'm more used to Java, so I'd have like

   code here;
//Run the method

Thanks smiley
3  Using Arduino / Programming Questions / Re: Programming the adafruit wave shield? on: January 27, 2013, 01:24:33 pm
Ahhh, I get you, there's a libraries folder in the arduino program files part, I thought you meant libraries like my documents, my videos etc. I do apollogise for that. Now there are no errors coming up, I can;t thank you enough for your help and patience! Now I just need to reformat my SD card cuz if printed an error to the serial about the SD Card xD
4  Using Arduino / Programming Questions / Re: Programming the adafruit wave shield? on: January 27, 2013, 11:25:29 am
I installed all of the files/folders into C:\Users\Daniel\Documents\Arduino    This is where all of my Arduino sketches are saved, and that error, variable or field 'play' declared void, is the exact error. I downloaded the latest rar file from the ada site, like clicked on the WaveHC link, and went to the top link on the downloads page with the most recent date on it, found here   There is nothing higher than 1.0.
5  Using Arduino / Programming Questions / Re: Programming the adafruit wave shield? on: January 27, 2013, 10:38:55 am
Alright, so I downloaded the WaveHC folder and all the rest and put them all into my main sketches folder, restarted the IDE, and tried to run the daphc code that plays all WAV files on the SD card. I'm still getting thrown errors, such as "variable or field 'play' declared void" I don't understand why it will not work, I followed the readme file and did as it said.

 * This example plays every .WAV file it finds on the SD card in a loop
#include <WaveHC.h>
#include <WaveUtil.h>

SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the volumes root directory
WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

uint8_t dirLevel; // indent level for file/dir names    (for prettyprinting)
dir_t dirBuf;     // buffer for directory reads

 * Define macro to put error messages in flash memory
#define error(msg) error_P(PSTR(msg))

// Function definitions (we define them here, but the code is below)
void play(FatReader &dir);

//////////////////////////////////// SETUP
void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps for debugging
  putstring_nl("\nWave test!");  // say we woke up!
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad

  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!) 
    error("Card init. failed!");  // Something went wrong, lets print out why
  // enable optimize read - some cards may timeout. Disable if you're having problems
  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {   // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;                           // we found one, lets bail
  if (part == 5) {                     // if we ended up not finding one  smiley-sad
    error("No valid FAT partition!");  // Something went wrong, lets print out why
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(), DEC);     // FAT16 or FAT32?
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    error("Can't open root dir!");      // Something went wrong,
  // Whew! We got past the tough parts.
  putstring_nl("Files found (* = fragmented):");

  // Print out all of the files in all the directories. | LS_FLAG_FRAGMENTED);

//////////////////////////////////// LOOP
void loop() {

/////////////////////////////////// HELPERS
 * print error message and halt
void error_P(const char *str) {
  PgmPrint("Error: ");
 * print error message and halt if SD I/O error, great for debugging!
void sdErrorCheck(void) {
  if (!card.errorCode()) return;
  PgmPrint("\r\nSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  PgmPrint(", ");
  Serial.println(card.errorData(), HEX);
 * play recursively - possible stack overflow if subdirectories too nested
void play(FatReader &dir) {
  FatReader file;
  while (dir.readDir(dirBuf) > 0) {    // Read every file in the directory one at a time
    // Skip it if not a subdirectory and not a .WAV file
    if (!DIR_IS_SUBDIR(dirBuf)
         && strncmp_P((char *)&[8], PSTR("WAV"), 3)) {

    Serial.println();            // clear out a new line
    for (uint8_t i = 0; i < dirLevel; i++) {
       Serial.write(' ');       // this is for prettyprinting, put spaces in front
    if (!, dirBuf)) {        // open the file in the directory
      error(" failed");          // something went wrong
    if (file.isDir()) {                   // check if we opened a new directory
      putstring("Subdir: ");
      dirLevel += 2;                      // add more spaces
      // play files in subdirectory
      play(file);                         // recursive!
      dirLevel -= 2;   
    else {
      // Aha! we found a file that isnt a directory
      putstring("Playing ");
      printEntryName(dirBuf);              // print it out
      if (!wave.create(file)) {            // Figure out, is it a WAV proper?
        putstring(" Not a valid WAV");     // ok skip it
      } else {
        Serial.println();                  // Hooray it IS a WAV proper!;                       // make some noise!
        uint8_t n = 0;
        while (wave.isplaying) {// playing occurs in interrupts, so we print dots in realtime
          if (!(++n % 32))Serial.println();
        sdErrorCheck();                    // everything OK?
        // if (wave.errors)Serial.println(wave.errors);     // wave decoding errors

6  Using Arduino / Programming Questions / Re: Programming the adafruit wave shield? on: January 25, 2013, 03:19:18 pm
Alright, I'll do it all tomorrow, had a busy day and my head hurts, just want to call it a night. Thanks a lot though, smiley
7  Using Arduino / Programming Questions / Re: Programming the adafruit wave shield? on: January 25, 2013, 03:00:19 pm
I didn't even know there was a wave libary. Oh jees, I'm not having a good night haha. I just want to test my wave shield by playing a wav file on the SD card which I converted to WAV following the instructions on the adafruit site. That's it, once I've done that, I can work on the code for my project myself, but I need to know if the wave shield works or not. Can you help me out at all or should I just give up and call it a night? xD
8  Using Arduino / Programming Questions / Re: Programming the adafruit wave shield? on: January 25, 2013, 02:31:28 pm
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  while (wave.isplaying) {
  // do nothing while its playing
  // now its done playing

void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  // look in the root directory and open the file
  if (!, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  // ok time to play! start playback;

So, that's the code from the site, it was from a hyper link that was called something like "play one wav file all the way through once"
The error given is 'wave' was not declared in this scope.
9  Using Arduino / Programming Questions / Programming the adafruit wave shield? on: January 25, 2013, 02:08:05 pm
Ok, so I really am extremely new to all of the arduino related stuff, but I am a student and I really want to learn. I have just finished assembling the wave shield and it is connected to my arduino uno. I have formatted the SD card following the instructions on adafruit, and I have my files correctly formatted to. But, I have looked at the code on the site and it makes no sense to me. If I try to use it, the arduino software throws countless errors at me. All I want to do essentially, is have a program where if I press a button, play soundfile 1, if I press a different button, play soundfile 2 etc. Or, even just how would I write a program just to play a file on the SD card, and then I can figure out how to merge that into if statements myself, I just need some help with the initial code and how it works. Thanks.
10  Using Arduino / Project Guidance / Program the arduino to play a sound file?? on: January 19, 2013, 10:12:42 am
Ok, so I am really new to this stuff, but I am a student, and we have a project to do after doing some basics (lighting up LEDs, using switches, LCD screens etc.) So for my project, I wanted to create a simple instrument of some sort. So I was wondering, is there some way I could record individual notes, save them as an MP3/WAV/WMA or whatever to my computer, and then play them through either my computer or a piezo speaker/buzzer by using the arduino? My idea is using if statements, and going something like
if(LDR1 < 400){

So it would be like using your fingers to play the notes with light resistors. But honestly, I'm not sure what I'm doing at all. I want to learn, but I'm just struggling with this sort of stuff. Thanks for any help! smiley
Pages: [1]