Pages: [1]   Go Down
Author Topic: Help with tones please  (Read 233 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys, I'm working with Sparkfuns danger Shield and I am trying to have my slider produce one octave of the chromatic scale.
I tried this bit of code:
Code:
int NoteFind(int x){
      for(int i=0, baseline=0, topline=78; i<14;i++, baseline+= 78, topline+= 78)// 1026/13 =78.92
      {
    if (baseline< x <topline)
   {
     return Notes[i];
     break;
   }
    }
  }
Int x is my analogRead. The return value goes directly to my tone.play()
All I can get is a single, droned tone.
Can anybody help or explain?
Its worth noting changed the initialized value of "i" does affect the tone.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 19118
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This doesn't do what you think it does:

Quote
Code:
    if (baseline< x <topline)

Maybe you mean:

Code:
    if (baseline < x && x < topline)

Or something like that. You need two tests not one "combined" test.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh thank you very much... I thought I saw an example or something where they used that, but apparently I'm wrong...
Thanks it works fine!
Logged

Pages: [1]   Go Up
Jump to: