/*
Pitch follower
Plays a pitch that changes based on a changing analog input
circuit:
* 8-ohm speaker on digital pin 9
* photoresistor on analog 0 to 5V
* 4.7K resistor on analog 0 to ground
created 21 Jan 2010
modified 31 May 2012
by Tom Igoe, with suggestion from Michael Flynn
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Tone2
*/
void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
}
void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// print the sensor reading so you know its range
Serial.println(sensorReading);
// map the analog input range (in this case, 400 - 1000 from the photoresistor)
// to the output pitch range (120 - 1500Hz)
// change the minimum and maximum input numbers below
// depending on the range your sensor's giving:
int thisPitch = map(sensorReading, 400, 1000, 120, 1500);
// play the pitch:
tone(9, thisPitch, 10);
delay(1); // delay in between reads for stability
}
/* ผู้ติดตามสนาม เล่นสนามที่เปลี่ยนแปลงไปตามอินพุตแบบแอนะล็อกเปลี่ยนแปลง วงจร: 8 โอห์มลำโพงบนหมุดดิจิตอล 9 * photoresistor บนนะ 0 ถึง 5V * ตัวต้านทาน 4.7K บนอนาล็อก 0 พื้น สร้าง 21 2010 ม.ค. แก้ไข 31 2555 พฤษภาคม โดย Tom Igoe กับข้อเสนอแนะจาก Michael Flynnตัวอย่างรหัสนี้อยู่ในโดเมนสาธารณะ http://www.arduino.cc/en/Tutorial/Tone2 */{setup() เป็นโมฆะ เตรียมใช้งานการสื่อสารแบบอนุกรม (สำหรับการดีบักเท่านั้น): Serial.begin(9600)}{loop() เป็นโมฆะ อ่านเซ็นเซอร์: int sensorReading = analogRead(A0) พิมพ์เซ็นเซอร์อ่านเพื่อให้คุณทราบความ Serial.println(sensorReading) แผนที่ช่วงอินพุตแบบแอนะล็อก (ในกรณีนี้ 400-1000 จากใน photoresistor) ช่วงสนามออก (120-1500Hz) เปลี่ยนแปลงต่ำสุด และสูงสุดสำหรับการป้อนค่าเลขด้านล่าง ขึ้นอยู่กับช่วง ของให้เซนเซอร์ของคุณ: int thisPitch =แผนที่ (sensorReading, 400, 1000, 120, 1500); เล่นสนาม: โทน (9, thisPitch, 10); delay(1) ความล่าช้าในระหว่างอ่านเพื่อความมั่นคง}
การแปล กรุณารอสักครู่..

/ *เสียงคนสนิทเล่นสนามที่เปลี่ยนไปตามการเปลี่ยนแปลงแบบแอนะล็อกวงจร :* 8-ohm วิทยากร 9 พินดิจิตอล* โฟโตริซิสเตอร์ที่ 0 ถึง 5V .* 4.7k ตัวต้านทานต่อ Analog 0 ถึงพื้นดินสร้าง 21 ม.ค.แก้ไขวันที่ 31 พ.ค.โดยทอมอีโกด้วยคำแนะนำจาก ไมเคิล ฟลินน์โค้ดตัวอย่างนี้เป็นสมบัติสาธารณะhttp://www.arduino.cc/en/tutorial/tone2* /setup() { โมฆะ/ / การใช้งานการสื่อสารอนุกรม ( สำหรับการดีบักเท่านั้น ) :ต่อเนื่อง เริ่มต้น ( 9600 )}loop() { โมฆะ/ / อ่านเซ็นเซอร์ :1 sensorreading = analogread ( A0 )/ / พิมพ์เซ็นเซอร์อ่านเพื่อให้คุณทราบว่าช่วงของต่อเนื่อง println ( sensorreading )แผนที่อนาล็อกอินพุตช่วง / / ( ในกรณีนี้ , 400 - 1000 จากโฟโตริซิสเตอร์ )/ / ช่วงมืดออก ( 120 - 1500hz )/ / เปลี่ยนน้อยที่สุด และตัวเลขนำเข้าสูงสุดด้านล่าง/ / ขึ้นอยู่กับช่วงเซ็นเซอร์ให้ :แผนที่ ( sensorreading int thispitch = 400 , 000 , 120 , 1500 )/ / เล่นเสียง :โทน ( 9 , thispitch , 10 )หน่วง ( 1 ) ; / / ล่าช้าระหว่างอ่านเพื่อเสถียรภาพ}
การแปล กรุณารอสักครู่..
