Linking to C++ includes, or having a Dictionary or List template?

What else would you expect from a 14. year old with a giant ego, trying to act smart whilst he knows only some knowledge of high-level programming, and expects it to be a piece of cake down at MCU level. Well, it was sheert frustration that led to the messed up replies I have given. :confused:

Anyways, moving on, do arrays in arduino let you access array functions? or do you need to loop through values to change/find elements(idk if that made sense or not).

It sounds like you actually DON'T know much about C/C++ at all but only know your C#, very strange skill set in the programming world. The answer is yes, you go through your array to pick out values. If you are 14 years old, you really should have learned BASIC, Python, or C/C++ instead of C#. You got on the wrong boat. Stay a few hells away from Microsoft or Apple for that matter. The reason you can do fancy things with C# is that there is a huge (pronounced with mega-gigabytes accent) life support system on your windows PC to do such fancy things for you, including the "Diktionary", when you call Diktionary.do_this_thing_for_me(). You like any of these fancy things you are not going to live without windows PC environment.

It must be like a privileged (means rich) person when programming in C#. You tell your computer to do this fancy thing and lay back to see the thing done. Maybe you get to program a windows phone in a similar way with massively reduced comfort of living of the huge library. On arduino, there is nothing. You are as poor as that homeless guy on the street and have to look out for trouble all by yourself before trouble catches you. You want something done, you actually have to do it step by step all by yourself as there's no personal assistant to do your errands.

Back to programming world, if you don't know basic C/C++ to do things step by step and keep yourself out of trouble you should try to learn it or stay away from arduino. You can't just hand over a bunch of data and say sort the data. You will either write code to compare and sort them one by one or find a library to do this for you. You can't just call data.sort(). What code is going to be sorting?

If you are 14 years old, you really should have learned BASIC, Python, or C/C++ instead of C#. You got on the wrong boat.

Now, I have to disagree with this. Learning to think logically is a necessary skill for a programmer. It does not matter whether the programming language is COBOL, LIST, FORTRAN, Basic, C, C++, C#, Algol, Ada, APL, Java, or any of the hundreds of other languages available. Knowing one language makes it easier to pick up another. Know two or three, and adding another is pretty easy. It's the logical thinking that trips up so many people.

OP - I think its great that your are trying to learn any programming language. Far to many people your age think software comes from the iStore. They haven't any clue how it gets there. Don't let the negative comments in this thread, mine included get you down.

You do need to learn about the capabilities and limitations of the hardware, and the Arduino is a good place to learn that. If you can make the Arduino do things, you will be able to make other computers with more memory, faster speeds, etc. do great things, too. Just be sure to learn what the language and operating system is doing for you. The fact that C# does garbage collection for you means that people often forget that other languages do not. Things like reference counting and automatic deletion of objects lets people forget the memory management is a very important skill. When the OS appears to give you unlimited memory, it is easy to forget that there really is a limited supply, no matter what computer you are talking about, and using more memory than that has a high price.

I would like for you to (again) explain what you are trying to do. Perhaps it is not possible on the Arduino. Perhaps it will require external hardware to accomplish. Perhaps a realistic understanding of the Arduino will require you to change/simplify requirements.

visser:
Anyways, moving on, do arrays in arduino let you access array functions? or do you need to loop through values to change/find elements(idk if that made sense or not).

OK, back on topic then. :slight_smile:

It helps to be clear about your requirements, because then the answers can be more useful.

... do arrays in arduino ...

Let's get this part straight. Arduino uses C++. So you really are asking: "do arrays in C++ ..."?

There are a lot of good tutorials about C++ on the Internet. You can even work through a lot of that on your PC/Mac without having to even program a board, although there will be some differences. Differences simply because a microcontroller doesn't have a file system, stdin, stdout and so on.

I'm not sure what you mean by "access array functions". You can store functions in an array, if that's what you mean. You can do practically anything, whether or not it is a good idea is another thing.

I am trying to use the preference/attribute system to trigger tasks

Perhaps if you describe this - the real requirement - in more detail. We won't be impressed by a lot of technical jargon. What is impressive is a clear statement of what you are hoping to achieve.

Purely as an example:

I want to read three light sensors and three pressure sensors to make a burglar alarm. The amount of pressure, and amount of light, needed to trigger the alarm needs to be configurable. The alarm needs to operate during some hours and not others, also configurable. I am planning to arm/disarm it with an infrared remote.

We can help with that sort of stuff. And hey, we want to encourage youngsters to get involved.

Ok here is what I am trying to achieve. :).

I have some motors. Now, when a motor is set to a certain speed or direction. I want that value to be stored in an object. (Are templates used here?) Now once it is stored, the value needs to be accessed later as a condition for, a switch or if -statement. Now I know this can be simply done using a float as storage for the value. But I want to know, now, if there is any other way to do this? (My original thought was the attribute system I created in c# and convert it to c++. :l)

(Did I explain it well enough? :roll_eyes:)

visser:
Ok here is what I am trying to achieve. :).

I have some motors. Now, when a motor is set to a certain speed or direction. I want that value to be stored in an object. (Are templates used here?) Now once it is stored, the value needs to be accessed later as a condition for, a switch or if -statement. Now I know this can be simply done using a float as storage for the value. But I want to know, now, if there is any other way to do this? (My original thought was the attribute system I created in c# and convert it to c++. :l)

(Did I explain it well enough? :roll_eyes:)

That was pretty clear. If you want to use these attribute system you created in C#, maybe you should keep this logic on PC and use arduino just like a dummy. There is a firmware called firmata that does similar things. It only leaves little logic on arduino and most logic on PC to decide what to do. You can make C# send serial message to arduino, say M50+ for motor spin at 50 and in positive direction. Then arduino only processes these and does what it is told. The logic remains on your PC, unless you need this project mobile. If you need the project to be mobile, then I suggest you strip the system down to simple classes and you can still do it on arduino.

liudr:

visser:
Ok here is what I am trying to achieve. :).

I have some motors. Now, when a motor is set to a certain speed or direction. I want that value to be stored in an object. (Are templates used here?) Now once it is stored, the value needs to be accessed later as a condition for, a switch or if -statement. Now I know this can be simply done using a float as storage for the value. But I want to know, now, if there is any other way to do this? (My original thought was the attribute system I created in c# and convert it to c++. :l)

(Did I explain it well enough? :roll_eyes:)

That was pretty clear. If you want to use these attribute system you created in C#, maybe you should keep this logic on PC and use arduino just like a dummy. There is a firmware called firmata that does similar things. It only leaves little logic on arduino and most logic on PC to decide what to do. You can make C# send serial message to arduino, say M50+ for motor spin at 50 and in positive direction. Then arduino only processes these and does what it is told. The logic remains on your PC, unless you need this project mobile. If you need the project to be mobile, then I suggest you strip the system down to simple classes and you can still do it on arduino.

I need the project to be mobile...and what do you mean by strip it down to simple classes? ^.-
I've seen the c# serial communication, but I highly doubt I will be going that far.

The system also has a Java variant, because before I learnt c#, I did java so this was created.(Idk if this code below is useful or not. I'm just puttin' it out there.)

private final Map<String, Object> attributes = new HashMap<String, Object>();

	public void setAttribute(String string, Object object) {
		attributes.put(string, object);
	}

	@SuppressWarnings("unchecked")
	public <T> T getAttribute(String string) {
		return (T) attributes.get(string);
	}

	@SuppressWarnings("unchecked")
	public <T> T getAttribute(String string, T fail) {
		T object = (T) attributes.get(string);
		if (object != null) {
			return object;
		}
		return fail;
	}

	public void removeAttribute(String string) {
		attributes.remove(string);
	}

visser:
(Are templates used here?)

You can use templates. This is C++.

Now, when a motor is set to a certain speed or direction. I want that value to be stored in an object.

I don't want to seem obtuse, but I don't get this bit. You set the motor to a speed. So yes you can store that speed.

Now once it is stored, the value needs to be accessed later as a condition for, a switch or if -statement.

Naturally, or there isn't much point in storing it.

Now I know this can be simply done using a float as storage for the value.

True.

But I want to know, now, if there is any other way to do this?

Another, more complicated, way? Sure, but why bother?

I suspect you are coming from a world, a world that I have largely left behind me. In this world you download megabytes of libraries to do things in very fancy general ways. I bet you could use these libraries to store the data, serve it up on an HTML page, save it to a database, email it to your brother, and then send it to Twitter.

But we don't need all that complexity ... do we?

Keep it simple ...

float speed = 42;
float direction = 220;

Done.

Thanks. <3

I guess you get used to all the libraries available with Java and c# :open_mouth:

You can create a class that link a particular motor and speed value.

class motorWithSpeed
{
   int motorPin;
   int motorSpeed;

   motorWithSpeed(int pin);
   
   setSpeed(int speed);
   int getSpeed();
};

You can create an instance of that class:

motorWithSpeed speedy(3);

You can make that motor change speed:

speedy.setSpeed(160);

You can later determine how fast the motor is going:

int speedySpeed = speedy.getSpeed();

Only the class instance maintains the speed.

PaulS:
You can create a class that link a particular motor and speed value.

class motorWithSpeed

{
   int motorPin;
   int motorSpeed;

motorWithSpeed(int pin);
   
   setSpeed(int speed);
   int getSpeed();
};




You can create an instance of that class:


motorWithSpeed speedy(3);




You can make that motor change speed:


speedy.setSpeed(160);




You can later determine how fast the motor is going:


int speedySpeed = speedy.getSpeed();




Only the class instance maintains the speed.

OMG, I didn't think of using a class! (herpaderp) Thankyou paul! I will love you forever <3

You used the word "object" in your very first post. And C++.

C++ is basically an object-oriented language. Objects are created by classes.

http://www.cplusplus.com/doc/tutorial/classes/

An object is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable.