Show Posts
Pages: [1] 2 3 ... 53
1  Community / Bar Sport / Re: Hello, its ..... here ringing you from Windows, to tell you that you have a .... on: July 17, 2014, 10:02:56 am
I never answer calls from sources I don't recognize.
2  Using Arduino / Programming Questions / Re: Can the (if statement) have A counter on it? on: June 20, 2014, 10:18:15 am
Turning the Arduino off is not a simple task to accomplish, but 'stopping' the code can effectively be attained by simply putting the code into an infinite loop at the point you want to stop it.  IE:
Code:
while(1); //Infinite Loop of doing nothing

Be aware, the only way to get out of that infinite loop is to reset the Arduino.
3  Topics / Robotics / Re: Tracking position of an autonomous robot on: May 14, 2014, 12:56:42 pm
I think a Raspberry Pi is overkill for this, and it'll probably be so easy to implement with one that it wouldn't be any fun to build!

1. A Raspberry Pi is definitely NOT overkill for any autonomous robot.
2. A fully autonomous robot is going to be a nontrivial challenge to implement even with all the best hardware money can buy (short of just buying an already fully autonomous robot anyways).

Do some research on SLAM (Simultaneous Localization And Mapping).  If you don't want to use a pre-generated environment for navigation, you're going to want something with substantially more memory and processing power, otherwise you'll end up with a robot that moves at the pace of a snail, if not slower.
4  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.
5  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.
6  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.
7  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
Quote
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.
8  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.
9  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.
10  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

Code:
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(0x7D);
        Serial.write(*p++ ^ 0x20);
      } else {
        Serial.write(*p++);
      }
    }
}

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:

sendAnything(Serial);
sendAnything(someComplexList);
etc.

A more appropriate function name would be sendAnythingViaVoid_EvenIfItDoesntMakeSense().

Quote
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.

Quote
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.

11  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.
12  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.
13  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.
14  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.
15  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.
Pages: [1] 2 3 ... 53