Show Posts
Pages: 1 2 [3] 4 5 6
31  Using Arduino / Programming Questions / Re: Problem compiling when adding code for a 2nd tact button to act as a switch. on: February 23, 2013, 05:21:25 am
Sorry, forgot to paste ;]
sketch_feb19c.ino: In function 'void setup()':
sketch_feb19c:29: error: a function-definition is not allowed here before '{' token
sketch_feb19c:61: error: expected `}' at end of input

void setup()
  pinMode(inPin1, INPUT);
  pinMode(outPin1, OUTPUT);
  pinMode(inPin2, INPUT);
  pinMode(outPin2, OUTPUT);
Ok, missed that. Just add the } at the end of the function setup just like the error states.
32  Using Arduino / Programming Questions / Re: Problem compiling when adding code for a 2nd tact button to act as a switch. on: February 23, 2013, 05:16:16 am
 digitalWrite(outPin1, state1);

  previous2 = reading2;
  digitalWrite(outPin2, state2);

  previous2 = reading2;
Setting the previous2 from reading2 does not make much sense to me if nothing changed in between, but other than that, I can't guess what the error might be. Especially when reading2 is never even initialized.. previous1 never changes state either.
33  Using Arduino / Programming Questions / Re: Passing I/O functions to a class. on: February 23, 2013, 05:05:48 am
Yes, or you can just pass the object via reference to a class function. The & marks reference. You have the class already instantiated and you just write the function definition like this:
Execute(MyClass & rClass);
34  Using Arduino / Programming Questions / Re: Passing I/O functions to a class. on: February 23, 2013, 05:03:13 am
Something like this.
MyClass * pClass = new MyClass(var1, var2);
var1 and var2 are some variables, just to show that you can pass them into the constructor or Init(). However, I must warn you about using uninitialized pointer variables. You must set a value to the pointer. The example above would crash on the Init-call if the pointer was pointing to either 0 or some random place in memory.

A safer way would be to use reference like MyClass & rClass; but this requires that you pass the reference via the constructor. It would be too late in the Init() function.

The third way is to just instantiate it with MyClass oClass; but this means you can't pass any variables in the constructor and you'll have to set the Init variables separately or with the Init() function.

As for function pointers, I would rather use derived classes. Function pointers are used more in C, but in C++ it's kinda not necessary most of the time. There are object oriented principles that involve implementing a factory for the creation of different kinds of objects, but it would take a lot of time to get a hold of and on simple projects it would just overcomplicate things for what it's worth..

The Serial class is probably instantiated already somewhere. I haven't checked how that works. It looks like the begin() function is enough to initialize it. I haven't seen the need to derive from it, but it also looks like the LCD libraries for example do. I'm sorry I'm still a bit new to Arduino, but I'm not that new to object oriented programming.
35  Using Arduino / Programming Questions / Re: Help me for solve my code on: February 23, 2013, 04:34:51 am
Ok thanks all for question.
This code I simulate for maintance car every 800 Hrs,1200Hrs,2000Hrs,2400Hrs but in this case i use time for easy test

I think my program it's OK but function press button it's not suitable I wan to press and hold 30 sec for working ,don't press and working
It's up to you what you want it do after 30 seconds has passed. The hint we gave you just gives you the ability the measure that the time has passed. So, within that 30 seconds, do nothing, and after the condition returns true (> 30000UL), you do something. 30 seconds is a long time for holding a button though.
36  Using Arduino / Programming Questions / Re: Help me for solve my code on: February 23, 2013, 04:15:03 am
I use "j" for checking on time t = 1 min if press button SELECT show  
The point is that you could replace that for "loop" with j=1 and it would do exactly the same thing, always, after the "loop" has executed. Same thing with the other loop and i=1... We don't understand why do you run the loop once.
I didn't get your suggestion.
 I want to press and hole button until 30 sec it will doing next stage command.
You save the first time stamp with millis() to a variable, and then keep comparing has the 30 second or 30 000 millisecond mark been reached. When the difference is greater than the limit you proceed with the next stage. Oh, wait, I just repeated the previous answer, sorry..
37  Using Arduino / Programming Questions / Re: Passing I/O functions to a class. on: February 23, 2013, 03:58:50 am
I'm not fully grasping the problem here yet, but if you want to be able to use some interface within that class, can't you just have those interfaces as member variables of your class?

I'm assuming that the problem is that the base classes have function implementation by the same name. So, without changing the library functions, you need to access those classes via pointers, references or just instantiate the interface within your class. Just make sure it's initialized before using it. Typically the constructor would be short, and you would have an Init() function that must be called. You do not want exceptions thrown in either constructor or destructor, that's mostly the reason, I think.
38  Using Arduino / Programming Questions / Re: Changing Baud Rate Doesn't Work on: February 23, 2013, 02:47:51 am
Same program with the long delays

result: "nr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'ánr'"

And it has 5 second delays before calling serial begin and after, as well as a half second delay between loops.. this is plenty
You actually never mentioned is this result directly copy pasted from the serial monitor (with the wrong rate), or are you trying to receive the data with some other device. I'm guessing the former. Naturally the receiver has to receive the data at the same rate the sender is operating at. Same goes with the serial monitor on Arduino IDE. Or maybe you are not even using the IDE, I can't tell.
39  Using Arduino / Programming Questions / Re: Need assitance with code on: February 20, 2013, 03:44:36 pm
First try what holmes4 just posted. I'm curious why is there a delay after every line even if the part inside the condition was never executed in inputprint. Anyways, inputprint and UdpIR could both be restructured so that the first one takes inPut and instate as input parameters, and the second would take IR1 and IR2. No need for 40 functions that do practically the same thing. Only one call is different in each, and that's the part you parametrize. I also don't see the point of the for loop in each of the 40 functions unless you meant to repeat it more than once later in development. You can save several kilobytes. Serial library seems to take several kilobytes alone though.
40  Using Arduino / Programming Questions / Re: moisture sensors on: February 12, 2013, 01:05:52 am
Would that be pin1? That's because of the first if-else. You don't have anything that would turn valvePin4 HIGH, but then you have 1 in too many places. It does not look logical.

However, you can have more problems when the sensor readings change. Write it in pseudo code what you want happen, then design it further. I think what you want is that the pump would turn on when any of the valves need to be open. Then when all the valves are off, you might as well turn the pump off too. Now what happens is that if any of the valves turn off, so does the pump, and then on the second round it turns on (because of one sensor reading), and off again (because of another reading).

One tip I can give you is to use either int or bool variables for what state each element should be in, and then act on it decisively after the if-else conditions.
41  Using Arduino / Programming Questions / Re: Passing a function another function on: February 10, 2013, 04:14:13 am
I think (f); should read f(); in the function, but otherwise that should work. It's either that or (*f)(); but those parentheses should appear at the end anyways, because it's a function call, I think.

Maybe irrelevant, but personally, I find function pointers a little awkward to work with. You are in effect doing code injection in C, when this kind of thing would be a little easier to handle in C++, in my opinion. You could have a base class that wraps the function as a virtual and then inherit the base class and redefine that function in each inherited class. Or you could have a single class with a pointer to another class that executes the function. Surely, the Arduino environment can compile all this, right?
42  Using Arduino / Programming Questions / Re: Need help understanding a line in someone elses sketch on: February 08, 2013, 01:54:17 pm
That's a little awkward because objectPresent is defined as an int and (powerCount < powerCountThreshold) equals to either true or false. I guess it works because true can equal to 1 and false to 0 in the end. Then it's used in an equation power * objectPresent and for that you need a number int anyways.

Edit: In other environments, like Windows COM services, that wouldn't be a safe assumption at all...
43  Using Arduino / Programming Questions / Re: Compare Dates - Times on: February 05, 2013, 01:23:52 pm
In the end, time is defined as elapsed time unit from a specified starting point in something like unsigned long data type. The "start of the universe" can be defined as something like Jan 1st, 1970, for example. The time can be taken from an RTC, or it's just clock cycles from last power up.

Anyways, if you can convert whatever representation you have to, say, seconds, it's as easy as doing a regular comparison and you can do subtraction and all, and return that difference back to days, hours, minutes and so on. It would be a whole lot more complex trying to figure out comparisons in the component form. It would be a lot easier if the time was not represented in its component form in data structures, but as a simple unsigned 32- or 64-bit number. 32 bit will probably do if one second accuracy is enough..
44  Using Arduino / Displays / Re: using sprintf with a color O'LED display..... on: February 03, 2013, 03:39:28 pm
Try and update only the area that changes on screen. I'm not sure how imageSD function operates, but I'm guessing it causes a flicker when it's reloading the same image over and over again. Can you make it so that the image is only loaded once during setup(). However, the rest of program needs to make sure it does not clear the background too much. If that does not work the way you like, you may need to overlay the text with the image somehow in memory, but your microprocessor might not have enough memory for anything like that. I don't know is it possible to read video ram from this display. There might be something in the library that allowed you to limit flicker.

Edit: Ah, "TRANS" must mean transparent text. Never mind what I wrote then, I didn't get the full grasp of the problem yet. I think imageSD works by loading the image from SD to memory, and then you can use drawImage to send a command to the screen to display the selected image. I didn't think the analogRead, or what do you mean, could actually dim the screen or cause some similar effect. I must have missed something obvious..
45  Using Arduino / Programming Questions / Re: Run function only for a period of time on: February 03, 2013, 11:14:39 am
You mean for a specific amount of time from last reset or from a button press etc? As far as I know, millis() starts counting from zero after power on.

In any case, I would make the function define the action it should do and nothing more, and then have the running condition of that function in loop().
if (millis() - startTime < totalTime*1000*60)
Where startTime has been initialized either to 0, or millis() at a specific event depending on what you want to trigger it. I assume you mean this variable to contain this info, so take it out of myCount(). It should be initialized somewhere else, not all the time. The function myCount would get called for totalTime [minutes] in a loop.
Pages: 1 2 [3] 4 5 6