Go Down

Topic: Help with tones please (Read 251 times) previous topic - next topic

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: [Select]

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];

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.

Nick Gammon

This doesn't do what you think it does:

Code: [Select]
    if (baseline< x <topline)

Maybe you mean:

Code: [Select]
    if (baseline < x && x < topline)

Or something like that. You need two tests not one "combined" test.
Please post technical questions on the forum, not by personal message. Thanks!

More info:

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!

Go Up