11 years, 4 months ago.

Having some issues with declaring variables

I know that there has to be a way to declare variables, I just have not figured them out or I am doing them wrong. I am used to declaring variables the arduino IDE way, how do I do them with them KL25z? I am looking to have some global variables that I can write analog in values to and do some math to get what I want out of them. So if I can be pointed in the right direction I would be very happy indeed. I do love this little thing, just have to learn its quirks. My next project is going to be connecting this to the electric imp.

1 Answer

11 years, 4 months ago.

It works pretty much the same as in Arduino. If you want to have a global variable you should define them outside of any functions, at the top of your code.

So something like:

#include "mbed.h"

DigitalOut led(LED_RED); //This is in principle also a global variable
int global_int;

void myfunction( void ) {

}

int main() {

}

Accepted Answer

I am at work at the moment but tried it at the compiler and it worked. I will have to try this on my Mac at home when I get out of work. I know that I tried this. I feel kinda dumb at the moment.

posted by james golden 03 Jul 2013