Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************************
- * Arduino Theramin *
- * learnelectronics *
- * 10 JAN 2023 *
- * https://www.youtube.com/learnelectronics *
- * Adapted and modified from an original *
- * sketch by Øyvind Nydal Dahl *
- * see original sketch here: *
- * https://www.build-electronic-circuits.com/arduino-theremin/ *
- **************************************************************************/
- int analogPin = A0; // Input from photoresistor connected to A0
- int buzzerPin = 4; // Positive buzzer pin connected to pin 4
- long max_frequency = 2000; // Max frequency for the buzzer
- long frequency; // The frequency to buzz the buzzer
- int readVal; // The input voltage read from photoresistor
- void setup() {
- pinMode(buzzerPin, OUTPUT); // set a pin for buzzer output
- }
- void loop() {
- readVal = analogRead(analogPin); // Reads 0-1023
- frequency = (readVal * max_frequency) / 1023;
- tone(buzzerPin, frequency);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement