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

« back to all changes in this revision

Viewing changes to build/shared/examples/2.Digital/toneKeyboard/toneKeyboard.pde

  • 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
 
  keyboard
3
 
 
4
 
 Plays a pitch that changes based on a changing analog input
5
 
 
6
 
 circuit:
7
 
 * 3 force-sensing resistors from +5V to analog in 0 through 5
8
 
 * 3 10K resistors from analog in 0 through 5 to ground
9
 
 * 8-ohm speaker on digital pin 8
10
 
 
11
 
 created 21 Jan 2010
12
 
 Modified 4 Sep 2010
13
 
 by Tom Igoe 
14
 
 
15
 
This example code is in the public domain.
16
 
 
17
 
 http://arduino.cc/en/Tutorial/Tone3
18
 
 
19
 
 */
20
 
 
21
 
#include "pitches.h"
22
 
 
23
 
const int threshold = 10;    // minimum reading of the sensors that generates a note
24
 
 
25
 
// notes to play, corresponding to the 3 sensors:
26
 
int notes[] = {
27
 
  NOTE_A4, NOTE_B4,NOTE_C3 };
28
 
 
29
 
void setup() {
30
 
 
31
 
}
32
 
 
33
 
void loop() {
34
 
  for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
35
 
    // get a sensor reading:
36
 
    int sensorReading = analogRead(thisSensor);
37
 
 
38
 
    // if the sensor is pressed hard enough:
39
 
    if (sensorReading > threshold) {
40
 
      // play the note corresponding to this sensor:
41
 
      tone(8, notes[thisSensor], 20);
42
 
    } 
43
 
  }
44
 
  Serial.println();
45
 
}