zoukankan      html  css  js  c++  java
  • 用Tinkercad学arduino之 根据光亮度改变蜂鸣器音调

    /*
      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
    */
    
    int sensorReading = 0;
    
    void setup()
    {
      pinMode(A0, INPUT);
      Serial.begin(9600);
    
      pinMode(9, OUTPUT);
    }
    
    void loop()
    {
      // read the sensor
      sensorReading = analogRead(A0);
      // print the sensor reading so you know its range
      Serial.println(sensorReading);
      // map the sensor reading to a range for the
      // speaker
      tone(9, 440 * pow(2.0, (constrain(int(map(sensorReading, 0, 1023, 36, 84)), 35, 127) - 57) / 12.0), 1000);
      delay(10); // Delay a little bit to improve simulation performance
    }
  • 相关阅读:
    安卓第四周作业
    安卓作业。
    JSP第七周作业
    jsp第六周作业
    JSP第四周作业
    JSP第二次
    软件测试课堂练习
    JSP第一次
    Android页面
    Android作业
  • 原文地址:https://www.cnblogs.com/meetrice/p/14078023.html
Copyright © 2011-2022 走看看