Error: 'theremin' was not declared in this scope

Hello, I am having a very confusing problem.
When I use some code (I will post that later in message), it comes with a very confusing error message.

CODE:

/* Sweep
  by BARRAGAN <http://barraganstudio.com>
  This example code is in the public domain.

  modified 8 Nov 2013
  by Scott Fitzgerald
  http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>
#include "SR04.h"
#include "tones.h"
#include "Talkie.h"
#include "Vocab_US_Large.h"
#include "Vocab_US_TI99.h"
#define TRIG_PIN 12
#define ECHO_PIN 11
long toneVal;
int piezo = 3;
int fan = 10;
SR04 sr04 = SR04(ECHO_PIN, TRIG_PIN);
long a;
int button = 7;

int R = 4;
int G = 8;
int B = 2;

int state = 1;

int low = 50.96;
int med = 91.44;
int high = 160;

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards
Talkie voice;

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  Serial.begin(9600);
  pinMode(button, INPUT);
  pinMode(fan, OUTPUT);
  pinMode(piezo, OUTPUT);
  pinMode(R, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(B, OUTPUT);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  //close_alarm();
}

void loop() {
  //not_close();
  a = sr04.Distance();
  theremin(a);
  //  if (a < 30.48) {
  //    state = 1;
  //  }
  //  else if (a > 30.48) {
  //    state = 2;
  //  }
  //  if(state == 1) {
  //    close_alarm(100);
  //  }
  //  else {
  //    theremin();
  //  }
  //}

  int close_alarm(int duration) {
    digitalWrite(fan, HIGH);
    blink();
    close_warning(duration);
    digitalWrite(fan, LOW);
    return;
  }

  void not_close() {
    knob();
    theremin();
    return;
  }

  void theremin(int a) {
    toneVal = map(a, 1, 30, 1500, 31);
    if (toneVal > 100) {
      tone(piezo, toneVal);;
    }
    else noTone(piezo);
  }

  void knob() {
    val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
    val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
    myservo.write(val);                  // sets the servo position according to the scaled value
    delay(15);
  }

  void blink() {
    digitalWrite(R, HIGH);
    delay(50);
    digitalWrite(R, LOW);
    delay(50);
    digitalWrite(G, HIGH);
    delay(50);
    digitalWrite(G, LOW);
    delay(50);
    digitalWrite(B, HIGH);
    delay(50);
    digitalWrite(B, LOW);
  }

  void close_warning(int time) {
    delay(time);
    tone(piezo, 250);
    delay(time);
    noTone(piezo);
    delay(time);
    tone(piezo, 650, 500);
    delay(time);
    noTone(piezo);
    //  voice.say(sp2_DANGER);
    //  voice.say(spt_YOU);
    //  voice.say(spt_ARE);
    //  voice.say(spt_TOO);
    //  voice.say(sp4_CLOSE);
  }

ERROR MESSAGE:

C:\hi\hows\your\day\a_folder\Cool_code.ino: In function 'void loop()':
Cool_code:57:3: error: 'theremin' was not declared in this scope
   theremin(a);
   ^~~~~~~~
Cool_code:72:33: error: a function-definition is not allowed here before '{' token
   int close_alarm(int duration) {
                                 ^
Cool_code:80:20: error: a function-definition is not allowed here before '{' token
   void not_close() {
                    ^
Cool_code:86:24: error: a function-definition is not allowed here before '{' token
   void theremin(int a) {
                        ^
Cool_code:94:15: error: a function-definition is not allowed here before '{' token
   void knob() {
               ^
Cool_code:101:16: error: a function-definition is not allowed here before '{' token
   void blink() {
                ^
Cool_code:115:32: error: a function-definition is not allowed here before '{' token
   void close_warning(int time) {
                                ^
Cool_code:129:3: error: expected '}' at end of input
   }
   ^
exit status 1
'theremin' was not declared in this scope

I am sorry if this is a very dumb problem.
Thank you!

Your loop() doesn't have a closing "}".

Like @red_car says, you do not close loop() with a } before defining functions so all of those function definitions are inside the loop() function. You cannot have function definitions inside of another function, that is illegal.

Thank you so much! It works perfectly!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.