Go Down

Topic: Help with tones please (Read 267 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];
    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.

Nick Gammon

This doesn't do what you think it does:

Quote
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:
http://www.gammon.com.au/electronics

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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy