'A1' is not a type

Hi! I am relatively new to Arduino and I really need your help.

I have got an Errormessage that not even my teacher can solve.

Here's the part of my code with the error message:

#ifndef _DEFINES_H_
#define _DEFINES_H_

#include "Arduino.h"

// 4 LEDs
#define LED1    13
#define LED2    12
#define LED3    11
#define LED4    10

// 3 Buttons
#define BUTTON1 A1
#define BUTTON2 A2
#define BUTTON3 A3

// 1 Potentiometer
#define POT1    A0

// 1 Buzzer
#define BUZZER  3

// LEDs und Buttons als Array
#define NUM_LEDS    4
#define NUM_BUTTONS 3

#define PIN_LEDS    {LED1, LED2, LED3, LED4}
#define PIN_BUTTONS {BUTTON1, BUTTON2, BUTTON3}

/* Define shift register pins used for seven segment display */
#define DISP_CLK 7
#define DISP_DATA 8
#define DISP_STORE 4

#endif

And here my errormessage:

Arduino: 1.8.10 (Windows 10), Board: "Arduino Uno"

In file included from C:\Users\SiMi\Documents\Arduino\Ampel\AmpelKorrBRE\AmpelKorrBRE.ino:1:0:

Defines.h:13:17: error: 'A1' is not a type

 #define BUTTON1 A1

                 ^

sketch\Ampel.h:19:22: note: in expansion of macro 'BUTTON1'

     Button ServusBtn(BUTTON1, false);

                      ^~~~~~~

In file included from C:\Users\SiMi\Documents\Arduino\Ampel\AmpelKorrBRE\AmpelKorrBRE.ino:6:0:

Ampel.h:19:31: error: expected identifier before 'false'

     Button ServusBtn(BUTTON1, false);

                               ^~~~~

Ampel.h:19:31: error: expected ',' or '...' before 'false'

In file included from sketch\Ampel.h:4:0,

                 from sketch\Ampel.cpp:1:

Defines.h:13:17: error: 'A1' is not a type

 #define BUTTON1 A1

                 ^

sketch\Ampel.h:19:22: note: in expansion of macro 'BUTTON1'

     Button ServusBtn(BUTTON1, false);

                      ^~~~~~~

In file included from sketch\Ampel.cpp:1:0:

Ampel.h:19:31: error: expected identifier before 'false'

     Button ServusBtn(BUTTON1, false);

                               ^~~~~

Ampel.h:19:31: error: expected ',' or '...' before 'false'

sketch\Ampel.cpp: In member function 'void Ampel::ampeltimer()':

Ampel.cpp:43:7: error: invalid use of member function 'Button Ampel::ServusBtn(int, int)' (did you forget the '()' ?)

   if (ServusBtn.hasBtnClicked()) {

       ^~~~~~~~~

Ampel.cpp:43:7: error: invalid use of member function 'Button Ampel::ServusBtn(int, int)' (did you forget the '()' ?)

exit status 1
'A1' is not a type

As you can see Arduino.h is Included so that should not be the Problem.

I am using an Arduino UNO but untill now i did not get to the point where I could upload anything. And i don't know if that is important but I use a multifunction shield.

So please help me :-)

P.S. It is the first time I use this forum and english is not my main language so please don't be mad at be because I made some mistakes while posting this.

We need to see Ampel.h

Karma + for using code tags!

It is the first time I use this forum and english is not my main language

There are language specific sections of this forum. If there is one for your native language you may be better posting your question there but if you stay here we will do our best to help.

The A1 is declared in pins_arduino.h, as you can see it is not just a define, but a "static const uint8_t". The pins_arduino.h depends on the choosen Arduino board of course and it is used when compiling.

When you want to make a common file, the A1 is not yet set to a value and not even to a type.

It is best to create data in a *.c *.cpp or *.ino file, not in a header file. In the header file you can make external references to it.

TheMemberFormerlyKnownAsAWOL: We need to see Ampel.h

Ok, but our teachers want to have everything seperate so I will just post all .h and the .ino:

.ino

#include "Defines.h"

#include "SimpleTimer.h"
#include "Button.h"
#include "7seg.h"
#include "Ampel.h"


SimpleTimer ampeltimer1;
Ampel ampelNr1;

void setup() {
  Serial.begin(9600);
  while ( ! Serial);
}


inline void updateAll() {

  ampelNr1.update();
}


void loop() {
  updateAll();



}

7seg.h

#ifndef SEG7_H
#define SEG7_H

#include "Defines.h"


#define clk_Pin    7
#define data_Pin   8
#define store_Pin  4

#define NUM_OF_DIGITS 4

extern byte number7Seg[11];


class SEG7 {
  byte clkPin, dataPin, storePin;
  // segs[] stores bit pattern of each digit, which is sent to output latch by update()
  
  void shiftBit(bool data);
  void shiftByte(byte dataByte);

  byte buffer[NUM_OF_DIGITS] = {0,0,0,0};
  byte currentDigit = 0;
  
  
public:
  // constructor
  //// Original: SEG7(byte cp = 7, byte dp = 8, byte sp = 4);
  SEG7(byte cp = DISP_CLK, byte dp = DISP_DATA, byte sp = DISP_STORE);
  
  // set segments a ... h of digit 0 ... 3 in segs[]
  void setDigit(byte digit, byte segments);
  
  // show digits (shift content of seg[i] into SR and latch to output)
  void update();

  
  void shiftDigit(byte digit, byte segments);
  
  void clear();
  
  void writeDigit(byte digit, byte segments);
  
  void printDigit(byte digit, byte number);
  
  void printNumber(int nmbr, int leading0 = 1);
};

#endif

Ampel.h

#ifndef AMPEL_H
#define AMPEL_H

#include "Defines.h"

#include "7seg.h"
#include "Button.h"
#include "SimpleTimer.h"


class Ampel {
    SEG7 ampel7seg;
    SimpleTimer timer1;

    Button ServusBtn(BUTTON1, false);
    int servusBtnCount = 0;

    enum AmpelState {red, redyellow, green, greenflash, yellow, yellowflash};
    AmpelState ampelState = red; //// Ergänzt
    

public:

    void doRed();
    
    void doRedYellow();
    
    void doGreen();
    
    void doGreenflash();
    
    void doYellow();
    
    void doYellowflash();
    
    void update();
    
    void ampeltimer();

};

#endif

Button.h

#ifndef _BUTTON_H
#define _BUTTON_H

#include "Defines.h"

#include "SimpleTimer.h"


// Die vier Zustaende des Buttons
enum ButtonState {isPressed, bouncingOn, isReleased, bouncingOff};


class Button {
    byte pin;                 // der Arduino-Pin des Buttons
    bool isActiveHigh;        // der Zustand des Buttons wenn er gedrueckt ist
    unsigned long debounceMS; // Anzahl der Millisekunden bevor der Zustand
                              //   gewaechselt wird (= Entprellzeit)
    SimpleTimer timer;        // Timer, um die (stabile) Entprellzeit zu messen
    bool hasClicked = false;  // speichert einen Click bis zum naechsten
                              //   Auslesen mit hasBtnClicked()
    ButtonState state;        // der aktuelle Zustand des Buttons

  
public:
  Button(byte pin=A1, bool isActiveHigh=false, unsigned long debounceMS = 10): pin(pin), isActiveHigh(isActiveHigh), debounceMS(debounceMS) {
    this->state        = isReleased;
  
    pinMode(pin, INPUT);
  }

  void update();

  bool isBtnPressed()  { return state == isPressed  || state == bouncingOn;  }
  bool isBtnReleased() { return state == isReleased || state == bouncingOff; }

  bool peekHasBtnClicked() { return hasClicked; }
  bool hasBtnClicked() { bool r = hasClicked;  hasClicked = false;  return r; }
  
};

#endif

SimpleTimer.h

#ifndef ALL_INCLUDES
#define ALL_INCLUDES

#include "Defines.h"

//#include "Button.h"
//#include "7seg.h"
//#include "Ampel.h"

class SimpleTimer {
    unsigned long start, duration;
    bool running;
    
  public:
    SimpleTimer();
    void set(int d = 1000); 
    bool expired();            
    void clear();                  
    bool elapsed();
};
#endif

The Defines.h is the same as posted before.

And what do you mean with:

TheMemberFormerlyKnownAsAWOL: Karma + for using code tags!

I do not understand that.

Koepel: The A1 is declared in pins_arduino.h, as you can see it is not just a define, but a "static const uint8_t". The pins_arduino.h depends on the choosen Arduino board of course and it is used when compiling.

When you want to make a common file, the A1 is not yet set to a value and not even to a type.

It is best to create data in a *.c *.cpp or *.ino file, not in a header file. In the header file you can make external references to it.

Uhm, jeah. I am not shure if I understood that correctly. But next to how the defines work we are programming this for a multifunction shield for the UNO so this programm ore these Defines only have to work there. But you mean I just should move all the defines in a "Defines.cpp" and leave the .h empty?

Button ServusBtn(BUTTON1, false); What is that supposed to be ?
What is it doing in a class definition?

Did you write it?

TheMemberFormerlyKnownAsAWOL:
Button ServusBtn(BUTTON1, false); What is that supposed to be ?

Did you write it?

Its a mixture of Languages. it should be called ServiceButton. In that case the Trafficlight should blink but I am not there yet because without A1 working I can not test anything.

And Button is a class in Button.h

But what is the type of BUTTON1?
What is the name and type (boolean, I assume) of the variable to be defaulted to false?

TheMemberFormerlyKnownAsAWOL: But what is the type of BUTTON1? What is the name and type (boolean, I assume) of the variable to be defaulted to false?

Oh, thats what you ment. It is creates in Defines.h

#define BUTTON1 A1

The part that is not working.

No.
A class definition contains function prototypes.

That is NOT a function prototype.

TheMemberFormerlyKnownAsAWOL: No. A class definition contains function prototypes.

That is NOT a function prototype.

I am not shure if that is what you want but the function prototype of Button is in Button.h

public:
  Button(byte pin=A1, bool isActiveHigh=false, unsigned long debounceMS = 10): pin(pin), isActiveHigh(isActiveHigh), debounceMS(debounceMS) {
    this->state        = isReleased;
  
    pinMode(pin, INPUT);
  }

  void update();

What is it doing in Ampel.h?

Does the Ampel class have a private method called ServusBtn that returns a Button?

The compiler see it as a function prototype because it has the form <type> <name>(<arguments>);
And arguments in a prototype need to be types.

Perhaps you meant something more like:

  Button foo = ServusBtn(BUTTON1, false);

Which is the form for an instance variable declaration, <type> <name> = <expression>;

TheMemberFormerlyKnownAsAWOL: What is it doing in Ampel.h?

Does the Ampel class have a private method called ServusBtn that returns a Button?

I am creating a variable calles ServusBtn with the class Button. And to define a vew things i have got BUTTON1 anf false.

In Ampel.h I create the variable and the constructor is in Button.h

Ampel.h

Button ServusBtn(BUTTON1, false);

Button.h -> here is the class Button

Button(byte pin=A1, bool isActiveHigh=false, unsigned long debounceMS = 10): pin(pin), isActiveHigh(isActiveHigh), debounceMS(debounceMS) {
    this->state        = isReleased;
  
    pinMode(pin, INPUT);
  }

and in Defines.h i would like to define everything

#define BUTTON1 A1

But there he says the error:

exit status 1
'A1' is not a type

We seem to be going round in circles here.

Is there a language more suited in the International section of the forum?

TheMemberFormerlyKnownAsAWOL:
We seem to be going round in circles here.

Is there a language more suited in the International section of the forum?

Yeah, ther would be.

German.

So you think I should ask the same question there? Or can I move this thread?

I or another mod can move it

Do you want it moved ?

UKHeliBob: I or another mod can move it

Do you want it moved ?

Yes, please move it to the Language German. I thought that my english would be good enough but it seems as it is not.

Hi

Willkommen im deuten Teil des Forum - Sie wünschen? :)

Ich denke, daß die #define hier irgendwie durcheinander kommen. Versuche, spaßeshalber: const byte BUTTON1=A1; (statt #define BUTTON1 A1 )

Das bitte mit sämtlichen #define, Die Du erstellt hast. Das hat auch den Vorteil, daß der Kompiler mit den Typen was anfangen kann. Durchgehend GROSS schreibt man Variablen eigentlich nicht, wobei bei Konstanten hier wieder unterschieden wird - der Übersicht halber wäre meine Wahl: const byte _pinButton1=A1; //wenn's denn durchnummeriert sein muß

Was sagt der Kompiler dann dazu?

MfG

postmaster-ino:
Hi

Willkommen im deuten Teil des Forum - Sie wünschen? :slight_smile:

Ich denke, daß die #define hier irgendwie durcheinander kommen.
Versuche, spaßeshalber:
const byte BUTTON1=A1;
(statt #define BUTTON1 A1 )

Das bitte mit sämtlichen #define, Die Du erstellt hast.
Das hat auch den Vorteil, daß der Kompiler mit den Typen was anfangen kann.
Durchgehend GROSS schreibt man Variablen eigentlich nicht, wobei bei Konstanten hier wieder unterschieden wird - der Übersicht halber wäre meine Wahl:
const byte _pinButton1=A1; //wenn’s denn durchnummeriert sein muß

Was sagt der Kompiler dann dazu?

MfG

Zuerst habe ich von wo anders im Programm eine fehlermeldung bekommen die mich verwundert hat. Ich habe bei der definition einer Klassen Variable " > (Parameter, Parameter)" geschrieben und runde statt geschwungenen Klammern genommen.

Jetzt meine Frage an dich:
Ich habe aus spaß ein const byte zurückgestellt auf #define und es hat trotzdem alles geklappt und dann habe ich alles auf #define gestellt und es funktioniert immer noch!

Wieso kommt wenn ich einmal () statt {} nehme eine Fehlermeldung dass A1 nicht stimmt obwohl dass in einer anderen Datei ist??? Kannst du mir das erklären?

Und auf deine Frage warum ich dort alles GROSZ schreibe: haben uns unsere Lehrer so beigebracht.

Und danke für deine Hilfe! Wenigstens hat nach dem umstellen auf const byte der Compiler dann wahren Fehler angezeigt :slight_smile: