Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
|
 |
« Reply #15 on: July 12, 2012, 09:24:30 am » |
Because it is mostly unnecessary (I have written one in the last thirty years, but it was deep in a Linux device driver, and required to be signed-off by a director), and has the potential of producing spaghetti code.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Australia
Offline
Jr. Member
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
|
 |
« Reply #16 on: July 12, 2012, 09:27:08 am » |
SoftwareSerial RFID = SoftwareSerial(RFID_RX, RFID_TX);
pinMode(RFID_TX, OUTPUT);//Define RFID TX pin as OUTPUT (Not nessesary) pinMode(RFID_RX, INPUT);//Define RFID RX pin as INPUT (Nessesary) You have told the SoftwareSerial instance that the pins are its to manage. So, why are you diddling with them? I'm changing their pinModes (even though its not really needed) because thats what it does in the SoftwareSerial tutorial: http://arduino.cc/en/Reference/SoftwareSerialAvailable
|
|
|
|
|
Logged
|
|
|
|
|
Australia
Offline
Jr. Member
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
|
 |
« Reply #17 on: July 12, 2012, 09:28:13 am » |
Because it is mostly unnecessary (I have written one in the last thirty years, but it was deep in a Linux device driver, and required to be signed-off by a director), and has the potential of producing spaghetti code.
Fair enough. It just seemed convenient and quick. Its not like I used it a lot, only once.
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26025
Solder is electric glue
|
 |
« Reply #18 on: July 12, 2012, 09:31:38 am » |
Once is once too many. Simply a GOTO is not a structured piece of code, it can be used to jump into the middle of structures that have not been set up with totally unpredictably consequences. If you feel the need to use a GOTO then you have not thought out the problem correctly.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
|
 |
« Reply #19 on: July 12, 2012, 09:33:16 am » |
See what I mean about attracting flak? 
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Australia
Offline
Jr. Member
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
|
 |
« Reply #20 on: July 12, 2012, 09:34:29 am » |
See what I mean about attracting flak?  Yep  I didn't realise that Goto was such a taboo! It must be drilled into your heads at uni!
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 334
Posts: 36449
Seattle, WA USA
|
 |
« Reply #21 on: July 12, 2012, 09:37:23 am » |
I'm changing their pinModes (even though its not really needed) because thats what it does in the SoftwareSerial tutorial: It's on the internet. It must be right. Not in this case: SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) : _rx_delay_centering(0), _rx_delay_intrabit(0), _rx_delay_stopbit(0), _tx_delay(0), _buffer_overflow(false), _inverse_logic(inverse_logic) { setTX(transmitPin); setRX(receivePin); } And, what does setTX do? void SoftwareSerial::setTX(uint8_t tx) { pinMode(tx, OUTPUT); digitalWrite(tx, HIGH); _transmitBitMask = digitalPinToBitMask(tx); uint8_t port = digitalPinToPort(tx); _transmitPortRegister = portOutputRegister(port); } And setRX? void SoftwareSerial::setRX(uint8_t rx) { pinMode(rx, INPUT); if (!_inverse_logic) digitalWrite(rx, HIGH); // pullup for normal logic! _receivePin = rx; _receiveBitMask = digitalPinToBitMask(rx); uint8_t port = digitalPinToPort(rx); _receivePortRegister = portInputRegister(port); } So, the pin modes have already been set when you diddle with them.
|
|
|
|
« Last Edit: July 12, 2012, 09:40:00 am by PaulS »
|
Logged
|
|
|
|
|
Australia
Offline
Jr. Member
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
|
 |
« Reply #22 on: July 12, 2012, 09:44:58 am » |
I'm changing their pinModes (even though its not really needed) because thats what it does in the SoftwareSerial tutorial: It's on the internet. It must be right. Not in this case: SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) : _rx_delay_centering(0), _rx_delay_intrabit(0), _rx_delay_stopbit(0), _tx_delay(0), _buffer_overflow(false), _inverse_logic(inverse_logic) { setTX(transmitPin); setRX(receivePin); } And, what does setTX do? void SoftwareSerial::setTX(uint8_t tx) { pinMode(tx, OUTPUT); digitalWrite(tx, HIGH); _transmitBitMask = digitalPinToBitMask(tx); uint8_t port = digitalPinToPort(tx); _transmitPortRegister = portOutputRegister(port); } And setRX? void SoftwareSerial::setRX(uint8_t rx) { pinMode(rx, INPUT); if (!_inverse_logic) digitalWrite(rx, HIGH); // pullup for normal logic! _receivePin = rx; _receiveBitMask = digitalPinToBitMask(rx); uint8_t port = digitalPinToPort(rx); _receivePortRegister = portInputRegister(port); } So, the pin modes have already been set when you diddle with them. Well it was on the official Arduino page, which is supposed to be moderated by experts like you and your counterparts, so it's not like I grabbed it off Wikipedia and stuck it in my code. Either way, nowhere have I read that you don't need to do that (At least anywhere on here), so obviously I'm not the only one, and no harm was done - the code works perfectly fine - so I don't think that any of this matters.
|
|
|
|
« Last Edit: July 12, 2012, 09:47:32 am by Koop »
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 334
Posts: 36449
Seattle, WA USA
|
 |
« Reply #23 on: July 12, 2012, 09:52:15 am » |
Well it was on the official Arduino page, which is supposed to be moderated by experts like you and your counterparts The official Arduino page contains many, many errors. Not a one of us "experts" or moderators can change the official Arduino page. I didn't mean to come across too hard on the issue. The pins belong to the instance (and it doesn't matter what the instance is an instance of), so they should not be diddled with by you (or any one else). Only the class that you give them to should diddle with them. You can, of course, look at the code, like I did, to see what is necessary, and what isn't, in the future. (That has to be a record for the number of commas I've ever put in one sentence.)
|
|
|
|
|
Logged
|
|
|
|
|
Australia
Offline
Jr. Member
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
|
 |
« Reply #24 on: July 12, 2012, 10:00:47 am » |
I didn't mean to come across too hard on the issue. The pins belong to the instance (and it doesn't matter what the instance is an instance of), so they should not be diddled with by you (or any one else). Only the class that you give them to should diddle with them.
You can, of course, look at the code, like I did, to see what is necessary, and what isn't, in the future. Thanks for that. Its hard to 'read' a person's emotions with only text to go by, and I thought that you were being one of those annoying nit-pickers, but you weren't so thats good  The official Arduino page contains many, many errors. Not a one of us "experts" or moderators can change the official Arduino page. Well that's not good is it :/ It should be checked for errors more frequently... and all examples I've ever seen do the same thing I did so it must be stemming from that one coding mistake. Thanks for all your help. I'll be sure to read the header files before I do anything with libraries again. Thanks to you all, Koop
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26025
Solder is electric glue
|
 |
« Reply #25 on: July 12, 2012, 11:12:48 am » |
It must be drilled into your heads at uni! A bit condescending. When I went to Uni there was no instruction about code. We had to learn it ourselves. When I taught at Uni, I never introduced it as a valid instruction.
|
|
|
|
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3117
|
 |
« Reply #26 on: July 12, 2012, 11:24:46 am » |
Some of us never attended a university.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
|
 |
« Reply #27 on: July 12, 2012, 11:41:56 am » |
Me neither.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14101
Lua rocks!
|
 |
« Reply #28 on: July 12, 2012, 06:49:24 pm » |
At my first technical programming job I handed in my first piece of code to my supervisor. He said "rewrite it without the gotos". I did that, and haven't used them since.
I can think of one place where a goto might be useful, and that is in the regular expression library where an expert (Roberto Ierusalimschy) used it in one place in order to avoid consuming the stack when doing tail recursion. This is a guy who knows what he is doing. He is an associate professor of Informatics and a compiler-writer (Lua).
If you are trying to avoid using the stack, when doing tail recursion, fair enough.
For other cases, you don't need goto, and they obscure what the code is doing.
|
|
|
|
|
Logged
|
|
|
|
|
Australia
Offline
Jr. Member
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
|
 |
« Reply #29 on: July 13, 2012, 01:58:28 am » |
A bit condescending. Some of us never attended a university. Sorry, Grumpy_Mike, AWOL and dxw00d! In no means was that meant to be condescending, I just assumed that seeing as though you guys are so good at this, and you knew to never, EVER, use a goto (except in the circumstance said by Nick) you had some form of tertiary education on the matter. Being a schoolkid, I've never experienced uni or TAFE or community college or any tertiary education, so I have no idea of how or what they teach you there. It was just an (obviously uneducated) guess 
|
|
|
|
« Last Edit: July 13, 2012, 02:09:35 am by Koop »
|
Logged
|
|
|
|
|
|