Pages: 1 [2]   Go Down
Author Topic: iTunes to Arduino  (Read 1956 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ugh, this is really starting to piss me off now.....

It's repeatedly printing to the terminal again. I can't see why, it may be skipping the "if" statement?

Code:
String originalFile;
String currentFile;
PFont font;


void setup() {
  size(400,400);
  font = loadFont("CourierNew36.vlw");
  String[] original = loadStrings("nowplaying.txt");
  originalFile = original[0];
}
void draw() {
  
  String[] current = loadStrings("nowplaying.txt");
  currentFile = current[0];
  if (currentFile!=originalFile) {
    originalFile = currentFile;
    print(originalFile);
    textFont(font);
    text(originalFile,20,200);
    saveStrings("data\\original.txt",current);
  }
}
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46255
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Add some more print statements, to print identifying data ("Current file: " or "Previous file: ") as well as the originalFile and currentFile variable contents.

It is possible that loadStrings is not doing exactly what you expect, or that it is not accessing the file that you think it is, or that the application that is writing to the file is appending data, not replacing it.

A little delay in the draw function would not be a bad thing. Perhaps the other application never gets a chance to write to the file, since it is always busy.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31550
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it may be skipping the "if" statement?

Note the if don't work with strings you know.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Note the if don't work with strings you know.

then how would i have a conditional statement?
« Last Edit: October 18, 2010, 11:33:08 am by wootwootman » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46255
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Note the if don't work with strings you know.
Good point.

You need to use
Code:
if(!currentFile.equals(originalFile))
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It worked!

well, i had to add +"\n" to the print statement, and ill probably change the whole line to

Code:
print("Now Playing: " +originalFile+ "\n");

maybe in the future ill add more song data, but if i do i can easily build off of this.

I just realized that upon first starting the winamp, it clears the  text file, so the sketch crashes, but i think theres a setting in the plugin to change that. EDIT: There is, now it no longer initializes the file.

Also, when the first song plays, "current" was equal to "original" so i added another condition and int in order to make sure it prints the first song the first time.

Here's my current build, sans serial
Code:
String originalFile;
String currentFile;
PFont font;
int i=0;

void setup() {
  size(400,400);
  font = loadFont("CourierNew36.vlw");
  String[] original = loadStrings("nowplaying.txt");
  originalFile = original[0];
}
void draw() {

  String[] current = loadStrings("nowplaying.txt");
  currentFile = current[0];
  if((currentFile.equals(originalFile))&& (i==0)){
    print(originalFile+"\n");
    textFont(font);
    text(originalFile,20,200);
    i++;
    
  }
  
  else if(!currentFile.equals(originalFile))
 {
    originalFile = currentFile;
    print(originalFile+"\n");
    textFont(font);
    text(originalFile,20,200);
    saveStrings("data\\original.txt",current);


  }
}
« Last Edit: October 18, 2010, 04:55:37 pm by wootwootman » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46255
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could simplify the code a bit, since you want to print serial data when the current file is not equal to the previous file OR i is 0:
Code:
if(!currentFile.equals(originalFile) || i == 0)
{
   // send the file name
}

There is no reason that I can see for the call to saveStrings.

I still recommend adding a small delay in draw(). There is no reason the read the file millions of times a second. A 100 millisecond pause would result in the song changing but the LCD not being updated for 1/10th of a second.

You might look at what other data is available about the file, too, and see what changes. If you can look at the time of last modification of the file, and that changes when winamp updates it, you could send new serial data only when the time stamp changes.

Anyway, good job persevering and getting something working.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i understand about the delay, so ill definitely put one of those in, but i wont really be able to test this out until i receive all the parts and actually build it. i found everything on ebay, all from china, so itll be a while before everything gets here. also i have yet to figure out what type/size of board to solder everything onto.

ill update this once i get everything!
Logged

Pages: 1 [2]   Go Up
Jump to: