Hello guys,
I get a String '01010101' and want to push it into a shift register:
unsigned char sr1 = byte(atoi(sCmd.substring(0,8).c_str()));
then:
shiftOut(dataPin, clockPin, LSBFIRST, sr1);
Any ideas why it wont work?
Thanks, Ronny.
Hello guys,
I get a String '01010101' and want to push it into a shift register:
unsigned char sr1 = byte(atoi(sCmd.substring(0,8).c_str()));
then:
shiftOut(dataPin, clockPin, LSBFIRST, sr1);
Any ideas why it wont work?
Thanks, Ronny.
atoi() requires a decimal representation of the number; you can use e.g strtoul() which allows to specify the base.
unsigned char sr1 = byte(atoi(sCmd.substring(0,8).c_str()));
This code is crap. You have no way of knowing what the substring actually is. You have no way of knowing what atoi() actually returned. Why are you using the stupid byte() macro to replace a cast, casting the int to a byte and then storing the result in a char?
Use some intermediate variables, so you can debug.
Use casts, not the stupid macros the Arduino team provides.
Use APPROPRIATE casts.
The code does something. You expect it to do something. You are the ONLY one that knows either of those things.
Sorry guts, im just beginning.
the code above was one of a million trials.
Im still not smarter
Any ideas why it wont work?
It does work. Perfectly. Your expectations are wrong.
But, since you didn't tell us what it actually does, or what your expectations are, as was requested, we can't help.
I got a shift register and i want to switch 01010101
shiftOut(dataPin, clockPin, LSBFIRST, sr1);
PS: sorry, english isnt my language .
We do not know what the sub string is that is created from the String.
We do not know what value atoi() created from the substring.
We do not know what value was assigned to sr1.
Why do we not know any of these things?
Your arrogance sucks!!!
Anyone else any idea?
Ronnybaby:
Your arrogance sucks!!!Anyone else any idea?
You complete lack of effort is what sucks.
Ronnybaby:
Your arrogance sucks!!!
Take a look at the number of posts Paul has made and the number of Karma points he's earned. He's probably seen issues similar to your over a thousand times and gets a little put off when people ignore what he's saying. Put your feelings on the shelf for a minute and look at the suggestions he's making...they work towards solving your problems.
As a general rule, always do a google search on the topic before posting. If nothing else, it will focus your question. I googled "Arduino and shift registers" and got over 200,000 hits. Surely, a couple of those will be of help. If not, be as specific as you can, follow the suggestions by Nick Gammon's post at the top of this Forum, and then ask your question. If Paul (and the rest of us) see your effort before posting here, I think you will find this group to be very helpful.