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

Hi all,

It's not the greatest of arduino projects but i came up with it in chemistry so... ;D

it basically changes the pitch on the reading of the potentiometer. Incredibly simple and great for people just finished the LED 'Phase'

Code:
/*
  PitchChanger
  
  Uses a potentiometer to control the pitch of a speaker.
  
  The circuit:
  * Potentiometer with middle pin connected to analog pin 0
  (with other pins connected to ground and +5V.
  
  * The speaker connected from digital pin 8 to ground.
  
  Created 5 May 2010
  By Jacob Simpson
  
  Based on an idea for an 'Annoy-a-Tron' customised for Arduino.
  
  */
  
  // Constants won't change. They're used here to set pin numbers:
  
  const int potPin = 0; // Potentiometer connected to Analog pin 0.
 
 // Variables will change:
  int val = 0; // Variable for reading the potentiometer.
  
  void setup()  {
  }
  
  void loop()  {
    tone(8, val); // Play tone on pin 8 at the frequency set by the potentiometer
  }

Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your example is missing the part where you read the pot's value?

Lefty
Logged

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

Just tried it and it doesn't Seem to work, any way I can change the code?
Logged

Scotland
Offline Offline
Edison Member
*
Karma: 24
Posts: 1212
Have you had your Arduino fix today?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Where do I start . . .

Define your analog pin as in input,
Read the input from this pin,
scale it to the tone function.

All the info is available in this forum, as well as in the reference supplied with the IDE download.

 smiley-wink Hope this gives you some pointers.

Cheers

Spycatcher2k
Logged

Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Toronto, ON
Offline Offline
Full Member
***
Karma: 10
Posts: 233
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this:

Code:
void loop()
{
  val = map(analogRead(potPin), 0, 1023, 100, 1000);
  tone(8, val);
}

You can play with the map() values (the 100 and 1000 numbers).

More info here:

http://itp.nyu.edu/physcomp/Labs/ToneOutput

b
Logged


Pages: [1]   Go Up
Jump to: