Was assigned to fixing an error in coding. Unfortunately, we have no idea what to do after a few attempts.
The code is here:
/**
2 * Copyright (c) 2015 by http://www.electrominds.com
3 * Simple Arduio Theremin "Theremino" Project
4 * Project URL: ElectroMinds.com
5 *
6 * This file is free software; you can redistribute it and/or modify
7 * it under the terms of either the GNU General Public License version 2
8 * or the GNU Lesser General Public License version 2.1, both as
9 * published by the Free Software Foundation.
10 *
11 * Required libraries:
12 * NewPing: Google Code Archive - Long-term storage for Google Code Project Hosting.
13 * toneAC: Google Code Archive - Long-term storage for Google Code Project Hosting.
14 */
15
16 include <NewPing.h>
17 include <toneAC.h>
18
19 define DEBUG false // Set to true to enable Serial debug
20 define TONE_PIN 8
21 define TONE_VOLUME 10 // 1-20
22 define TRIGGER_PIN 12 // Board pin tied to trigger pin on the ultrasonic sensor.
23 define ECHO_PIN 11 // Board pin tied to echo pin on the ultrasonic sensor.
24 define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
25
26 NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
27
28 void setup()
29 if (DEBUG) {
30 Serial.begin(115200);
31 Serial.println("Theremino starting");
32 }
33 }
35 void loop() {
36 delay(30); // Wait 30ms between pings (about 33 pings/sec). 29ms should be the shortest delay between pings.
37 unsigned long uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
38
39 if (DEBUG) Serial.println(uS);
40
41 if (uS > 2000) { // Range is about 0-30 cm from sensor
42 toneAC(0); // Turn sound off when not in range
43 if (DEBUG) Serial.println("No tone");
44 } else {
45 int freq = 2000 - uS / 1.5; // Get sound frequency
46 toneAC(freq, TONE_VOLUME); // Play it!
47 if (DEBUG) Serial.println(freq);
48 }
49 }