Hello I had some trouble with my code here is the full error message:
Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Uno"
sketch_feb08b_v.2:28: error: expected initializer before 'if'
if (DEBUG) { {
^
exit status 1
expected initializer before 'if'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
And here is my full code:
/* Copyright (c) 2015 by http://www.electrominds.com
* Simple Arduio Theremin "Theremino" Project
* Project URL: http://www.electrominds.com/projects/simple-arduino-theremin-theremino
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*
* Required libraries:
* NewPing: https://code.google.com/p/arduino-new-ping/downloads/detail?name=NewPing_v1.5.zip
* toneAC: https://code.google.com/p/arduino-tone-ac/downloads/detail?name=toneAC_v1.2.zip
*/
#include <NewPing.h>
#include <toneAC.h>
#define DEBUG false // Set to true to enable Serial debug
#define TONE_PIN 8
#define TONE_VOLUME 10 // 1-20
#define TRIGGER_PIN 12 // Board pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Board pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup()
if (DEBUG) { {
Serial.begin(115200);
Serial.println("Theremino starting");
}
}
void loop() {
delay(30); // Wait 30ms between pings (about 33 pings/sec). 29ms should be the shortest delay between pings.
unsigned long uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
if (DEBUG) Serial.println(uS);
if (uS > 2000) { // Range is about 0-30 cm from sensor
toneAC(0); // Turn sound off when not in range
if (DEBUG) Serial.println("No tone");
} else {
int freq = 2000 - uS / 1.5; // Get sound frequency
toneAC(freq, TONE_VOLUME); // Play it!
if (DEBUG) Serial.println(freq);
}
}