Show Posts
Pages: [1] 2 3 ... 52
1  Using Arduino / Programming Questions / Re: issue with millis() on: September 30, 2013, 08:41:59 pm
Looks like the problem is that you're repeatedly setting Timer = millis(), which consequently means that millis() - Timer a few lines later is always going to be 0.  You should only be setting Timer once.  You need a state variable or two to keep track of what code should and shouldn't be running, namely when the pump is off, and then when it is on.
2  Using Arduino / Programming Questions / Re: Problem with sizeof in a function on: September 22, 2013, 10:22:39 pm
The strlen() function only works on char arrays, not String objects.  String objects have their own built in length() method that returns the length of their string.
PeterH showed an example of how to use strlen with char arrays.
cbaldan showed an example of how to use the length() method of the String class.

If you try using strlen() with a String object, it isn't going to work.
If your char array isn't properly null terminated, strlen() isn't going to work.

If you have code using strlen() with a null terminated char array, and you aren't getting the result you expect, post it so we can see what the issue is.
3  Community / Bar Sport / Re: If Hitler had of won the war.... on: September 15, 2013, 08:56:52 pm
I mean, there would be so much suffering going on, mass exterminating  for example, but come 90 years later if that no longer took place and things settled, would life now 90 years later be better? in some ways?

You honestly believe somebody like Hitler would have been able to successfully eliminate all the racial and cultural hatred and bigotry that exists in this world.  He was easily one of the worst offenders of such in human history.  It's simply na├»ve to think that hatred and bigotry would be able to defeat hatred and bigotry.
4  Using Arduino / Motors, Mechanics, and Power / Re: Can 12v 100mA solar panel run the Arduino and one question about Li-Ion battery on: September 06, 2013, 02:09:32 pm
The panels will act as a charger for the lipo

Do NOT do this without the proper lipo charging circuitry in place.  Plugging solar panels directly into a lipo is a recipe for disaster.  Your project could quite literally go up in flames if you just dump unregulated current into a lipo battery.
5  Using Arduino / Project Guidance / Re: Running out on pins on my Uno ...... !! on: January 28, 2013, 12:21:27 am
Shift Registers may provide the IO expansion you need.  3 Arduino pins gets you 8/16/... additional outputs or inputs.
6  Using Arduino / Programming Questions / Re: A function to handle multiple datatypes on: November 02, 2012, 09:11:21 am

The cases to break type safety are when there are no better options available.  This is NOT one of those cases.

I'm sorry, but the approach I suggested to the OP (which was essentially the same as that already provided by Coding Badly), had absolutely nothing to do with templates. It was also perfectly "safe", general, and even elegant, if implemented correctly. It also happens takes up less space in flash, as I think I may have mentioned in passing.

I was not commenting on any code beyond what I quoted in my post.  I had no criticisms towards the code posted by Coding Badly because it was quite clear that it relied on void pointers.  My actual criticism was made quite clearly in my previous post.  Not just once, but twice, so I'm not going to bother reiterating it for a third time.

Second, any usage of void pointer is NOT perfectly "safe".  To paraphrase Indigo Montoya, "I do not think that word means what you think it means.".  There are acceptable uses of void pointer, even appropriate uses.  I never argued that there weren't, though you seem to be under the impression that I have.

My original question still stands to the OP, and to everyone in general even, what types of data are being transmitted that requires the use of void pointer.  Without that information, it seems rather shortsighted to me to claim any solution to the problem is the best solution.

If "type safety" is paramount before all other considerations in writing YOUR code, well, good luck to you.

Where did I state type safety was "paramount before all other considerations"?  I don't believe I did.  Actually, I'm absolutely positive that I did not.

You may want to work on your reading comprehension.  It appears to be a bit lacking.
7  Using Arduino / Programming Questions / Re: A function to handle multiple datatypes on: November 02, 2012, 07:36:12 am
Well whist you guys were fighting I tried this and it seems to work. Thanks

template <class T> void sendAnything(const T& value)
    const byte* p = (const byte*)(const void*)&value;
    unsigned int i;
    for (i = 0; i < sizeof(value); i++) {
      if (*p == 0x7E || *p == 0x7D) { //byte stuffing
        Serial.write(*p++ ^ 0x20);
      } else {

Casting a template argument in a generic function to a void pointer is a bad practice.  You've created a function that allegedly sends anything.  It will work with the intrinsic types and it will work with some class types, but it will definitely not send anything (although it will always send something, whether it makes sense or not).

The question that begs asking is, what data type are you attempting to transmit that requires casting to a void pointer (and then to a byte pointer)?

Your template function should be relying on either an overloaded Serial.write() method for sending the passed in data, or the user passing in the data in a form that is compatible with the Serial.write() method.  You're hiding a void cast inside a generic function.  Just to reiterate, bad practice.  

Your function would basically allow all sorts of nonsense code to compile.  ie:


A more appropriate function name would be sendAnythingViaVoid_EvenIfItDoesntMakeSense().

Well sorry, but actually, I do want to break type checking in some cases. And I do. And that is precisely what void* is for, both in C and C++ -- to work with a pointer without a type.

The cases to break type safety are when there are no better options available.  This is NOT one of those cases.

But if sharp objects make you nervous, you can always choose to use the safety scissors instead. Choices are good.
Choices are indeed good.  Veiled petty insults... another story.

8  Using Arduino / Programming Questions / Re: Is there a way to reference one variable with another? Preferably by name. on: October 18, 2012, 07:00:00 am
PaulS's suggestion to use a map seems ideally suited to this task.  No need to use tediously large switch statements or if/else if chains.
9  Using Arduino / Programming Questions / Re: C++ What is and isn't implemented in the Arduino IDE on: October 17, 2012, 07:24:47 pm
One thing you should probably understand is what is even meant by IDE, mainly because the only part of the Arduino IDE that's actually 'Arduino' is the editor.  The underlying library is AVR Libc, which you've been introduced to, the compiler is gcc, an open source compiler with an AVR compatible implementation, and avrdude is the program used to download the compiled binaries to the microcontroller.

If your real goal is to become proficient at programming, your best avenue honestly is to focus on learning C++ on the PC.  Remove the microcontroller from the equation.  Once you are proficient with C++ on it's own, it'll be far easier to make the transition to programming in the AVR environment.  There are far more resources for learning C++ than there are for learning AVR programming.  And honestly, a high percentage of the 'tutorials' out there for AVR programming are real good examples of how not to do things.
10  Using Arduino / Motors, Mechanics, and Power / Re: Using a motor control (forward/reverse) to control 2 motors, forward on: October 17, 2012, 03:42:54 pm
A motor controller is kinda overkill for single direction control, even if it's control of multiple motors.  Just use a transistor or FET (depending on  power requirements).  An h-bridge is only necessary for bi-directional control.
11  Using Arduino / Programming Questions / Re: More problems with attachInterrupt on: October 08, 2012, 09:38:22 am
How is the hall effect sensor attached to the Arduino and what is the intended behavior you are attempting to implement?

Just a guess here, but what you may be intending is to trigger one interrupt on the rising edge and one on the falling, not both on the falling edge.  If the hall effect sensor is tied to both input 2 and 3, then you will indeed trigger both interrupts essentially at the same time.
12  Using Arduino / Programming Questions / Re: Flushing Arduino on: October 05, 2012, 12:19:42 pm
That's either a bug in your new code, or a failure to upload the new code to the Arduino (and the IDE would have generated an error if that had occurred).  The act of uploading a new program overwrites the previous program, no other steps need to be taken.
13  Community / Bar Sport / Re: Why don't CPUs and microcontrollers operate on 24v? on: October 05, 2012, 12:18:06 pm
Modern high speed processors have another problem to deal with as well, electromagnetic interference.

Every conductor has some inductance rating, even if it's in the range of nano or pico henries.  While that may not sound like much, it does result in the generation of electromagnetic fields around those conductors as high speed signals run through them, and as internal traces on processors get smaller and smaller (the latest Intel i processors are built using 32nanometer traces), these miniscule electromagnetic fields can generate currents in neighboring paths, thus requiring the processors to run on increasingly lower and lower voltages to keep these fields small enough to mitigate such interference.
14  Using Arduino / Programming Questions / Re: problem with SoftwareSerial and servo libraries on: October 05, 2012, 12:09:31 pm
15  Using Arduino / Programming Questions / Re: Flushing Arduino on: October 05, 2012, 12:06:41 pm
Ummm... drop it in the toilet and hit the lever?

You need to clarify what you mean by 'flush the Arduino.'
Pages: [1] 2 3 ... 52