method not declared

Hi,

I'm trying to find a solution to resolve this problem but it seems that i'm getting stuck over here.

Basically i have this 3 files:

GamePad.ino:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once

#include "Arduino.h"
#include <SoftwareSerial.h>
#include <SdFat.h>
#include <DS3231.h>
#include <DFRobotDFPlayerMini.h>
#include <SPI.h>
#include "GamePad.h"


extern bool reset_var = false;

extern DS3231 rtc(SDA, SCL);
extern SdFat SD;
extern File myFile;
extern DFRobotDFPlayerMini myDFPlayer;
extern SoftwareSerial mySoftwareSerial(9, 10);
GamePadClass a;

void setup() {
	a.init();
}

void loop() {
	a.light(0);
	reset_var = false;
	delay(300);
	a.menu();
	while (reset_var == false) {
		a.light(0);
	}
}


GamePadClass.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "arduino.h"

const byte interruptPin = 3;
#define A 8
#define B 7
#define C 6
#define D 5
#define pin_button A0
#define pin_button2 A3
#define game_button A1
#define SD_CS_PIN 4

class GamePadClass
{
 private:

	 int led[10][2] = { { A, D },{ C, D },{ D, A },{ A, C },{ B, A },{ D, C },{ C, B },{ B, C },{ C, A },{ A, B } };

	 bool check_id = true;

	 int right_button;
	 int button;
	 int player_id = 0;
	 int gametype = 0;
	 unsigned int t_delay1 = 0;
	 unsigned int t_delay2 = 0;
	 int n_plays1 = 0;
	 int n_plays2 = 0;
	 int n_plays3 = 0;
	 unsigned long game_times[20];
	 int player = 0;
	 int n_button[20];
	 unsigned long start = 0, finish = 0;

	 int read_button();
	 void get_button();
	 int detect_button();
	 void jogo1();
	 void func_jogo1(int);
	 void jogo2();
	 void jogo3();
	 void func_jogo3(int x);
	 void turn_on(int pin[2]);
	 void turn_off(int pin[2]);
	 void erro(int x, int y);
	 
	 
	 void get_id();
	 bool read_settings();
	 void save_history(int x);
	 void play(int a);

 public:
	 
	 void menu();
	 void light(int x);
	 void init();
};

and GamepadClass.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "GamePadClass.h"

void GamePadClass::init()
{
	pinMode(A, INPUT);
	pinMode(B, INPUT);
	pinMode(C, INPUT);
	pinMode(D, INPUT);
	pinMode(interruptPin, INPUT_PULLUP);
	attachInterrupt(digitalPinToInterrupt(interruptPin), change_var, CHANGE);
	rtc.begin();
	mySoftwareSerial.begin(9600);
	if (!myDFPlayer.begin(mySoftwareSerial)) {
		erro(3, 0);
	}
	if (!SD.begin(SD_CS_PIN)) {
		erro(2, 0);
	}
	if (!read_settings()) {
		erro(2, 9);
	}
}

void change_var() {
	reset_var = true;
}

(in this one i got all the other methods declared but for the example is enough)

and i got these errors:
1
2
3
4
5
6
7
8
9
10
11
12
GamePadClass.cpp: In member function void GamePadClass::init()
 
GamePadClass.cpp: 12:55: error: 'change_var' was not declared in this scope
   attachInterrupt(digitalPinToInterrupt(interruptPin), change_var, CHANGE)
Error compiling project sources
Debug build failed for project 'GamePad'
 
GamePadClass.cpp: 13:2: error: 'rtc' was not declared in this scope
   rtc.begin()
 
GamePadClass.cpp: 14:2: error: 'mySoftwareSerial' was not declared in this scope
   mySoftwareSerial.begin(9600)

and more for every method i use from the externals classes.

Anyone know how to solve this?

PS: i already tried to have the objects of the externals classes as private on the GamepadClass and call them on the constructor using this->object = object, but keeps everything the same
Last edited on
Maybe this:
 
attachInterrupt(digitalPinToInterrupt(interruptPin), change_var, CHANGE);

should be this.
 
attachInterrupt(digitalPinToInterrupt(interruptPin), change_var(), CHANGE);


GamePadClass.cpp cannot see rtc. You've used it as is it's a class, but it needs to be declared.
Last edited on
working now. thanks
Topic archived. No new replies allowed.