~ubuntu-branches/debian/experimental/arduino/experimental

« back to all changes in this revision

Viewing changes to build/shared/examples/2.Digital/tonePitchFollower/tonePitchFollower.ino

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2012-03-11 18:19:42 UTC
  • mfrom: (1.1.5) (5.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120311181942-be2clnbz1gcehixb
Tags: 1:1.0.1~rc1+dfsg-1
New upstream release, experimental.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Pitch follower
 
3
 
 
4
 Plays a pitch that changes based on a changing analog input
 
5
 
 
6
 circuit:
 
7
 * 8-ohm speaker on digital pin 8
 
8
 * photoresistor on analog 0 to 5V
 
9
 * 4.7K resistor on analog 0 to ground
 
10
 
 
11
 created 21 Jan 2010
 
12
 modified 30 Aug 2011
 
13
 by Tom Igoe 
 
14
 
 
15
This example code is in the public domain.
 
16
 
 
17
 http://arduino.cc/en/Tutorial/Tone2
 
18
 
 
19
 */
 
20
 
 
21
 
 
22
void setup() {
 
23
  // initialize serial communications (for debugging only):
 
24
  Serial.begin(9600);
 
25
}
 
26
 
 
27
void loop() {
 
28
  // read the sensor:
 
29
  int sensorReading = analogRead(A0);
 
30
  // print the sensor reading so you know its range
 
31
  Serial.println(sensorReading);
 
32
  // map the pitch to the range of the analog input.
 
33
  // change the minimum and maximum input numbers below
 
34
  // depending on the range your sensor's giving:
 
35
  int thisPitch = map(sensorReading, 400, 1000, 100, 1000);
 
36
 
 
37
  // play the pitch:
 
38
  tone(9, thisPitch, 10);
 
39
 
 
40
}
 
41
 
 
42
 
 
43
 
 
44
 
 
45
 
 
46