Help Understanding a Statement

I'm new to the C++ language that is used for sketches. I've got some books and looked at programs but there is a statement in a program that I'm looking at which I can't understand. The statement is

PS2X ps2x; // create PS2 Controller Class

I understand // create PS2 Controller Class is a comment but the comment doesn't help me understand the rest of the line.

The question is what is the statement mean and what does it do?

The statement in context is as follows

#include <PS2X_lib.h> //for v1.6

/******************************************************************

  • set pins connected to PS2 controller:
    • 1e column: original
    • 2e colmun: Stef?
  • replace pin numbers by the ones you use
    ******************************************************************/
    #define PS2_DAT 8 //14
    #define PS2_CMD 11 //15
    #define PS2_SEL 10 //16
    #define PS2_CLK 12 //17

/******************************************************************

  • select modes of PS2 controller:
    • pressures = analog reading of push-butttons
    • rumble = motor rumbling
  • uncomment 1 of the lines for each mode selection
    ******************************************************************/
    #define pressures true
    //#define pressures false
    #define rumble true
    //#define rumble false

PS2X ps2x; // create PS2 Controller Class

//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you connect the controller,
//or call config_gamepad(pins) again after connecting the controller.

int error = 0;
byte type = 0;
byte vibrate = 0;

void setup(){

pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(9, OUTPUT);

Serial.begin(57600);

delay(300); //added delay to give wireless ps2 module some time to startup, before configuring it

//CHANGES for v1.6 HERE!!! *PAY ATTENTION

//setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
error = ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, pressures, rumble);

Just like:

int error = 0;

creates a new variable of type int named error, that line creates a new variable called ps2x that is of type PS2X. It is an object of the PS2X class.

You need to look up what an object is.

Basically it is a variable, like "int", but it can hold alot more information. Let me give you an example...

#include <Cars.h>

Car someCar; //create a new car that we call "someCar"

void setup() {
  //now that we have a car object named "someCar", we can set its variables. These variables will have been declared in the class, located in "Cars.h".
  someCar.make = "Honda"; //set our car's make
  someCar.model = "Civic"; //set our car's model
  someCar.year = 2004; //set our car's year
  someCar.miles = 50000; //set our car's odometer
  someCar.color = "BLUE";

  //objects can also have functions (aka methods), so you could do something like this
  Serial.println(someCar.getColor()); //this will print "BLUE"
}

void loop() {}

Ps991:
Basically it is a variable, like "int", but it can hold alot more information. Let me give you an example...

{sigh} In English, "allot" is a verb.
In English, "alot" is not even a word.

If you can't write your explanation in plain English ...yadda yadda. - AWOL

a lot / alot / allot. A lot, meaning a large amount or number of people or things, can be used to modify a noun. For example:- "I need a lot of time to develop this web site." It can also be used as an adverb, meaning very much or very often.

It says "alot", just don't focus on how spellcheck redlines it, because obviously spellcheck is wrong and I am right, like always...obviously...

Thank you Ps991! That helps

That helps

A lot or alot? :slight_smile:

Pete

I don't like "a lot" because you could say something like this:

I was cleaning a lot.

Was I cleaning a physical lot, like a parking lot, or was I cleaning a large amount?

Ps991:
I don't like "a lot" because you could say something like this:

I was cleaning a lot.

Was I cleaning a physical lot, like a parking lot, or was I cleaning a large amount?

Or you were cleaning the town and nagar panchayat of Alot in the Ratlam district of Madhya Pradesh, India, but don't know how the shift key works.

Ps991:
I don't like "a lot"....

Like it or not, "a lot" is English, "alot" is not. It's just a word that you've made up.

It's a perfectly cromulent word.

Was ist das "cromulent"?

?

Budvar10:
Was ist das "cromulent"?

?
Petrichor, Cromulent, and Other Words the Internet Loves | Merriam-Webster

Ha. I always liked "embiggen". (Mentioned in the article you linked, and from "The Simpsons".)

embiggen :o TGIF

Like it or not, "a lot" is English, "alot" is not. It's just a word that you've made up.

Irregardless, I just learnt it the wrong way and used this cromulent word alot out of habit; I thought I was embiggening my vocabulary...I guess not...

Ps991:
Irregardless, I just learnt it the wrong way and used this cromulent word alot out of habit; I thought I was embiggening my vocabulary...I guess not...

:smiley: