Pages: 1 [2]   Go Down
Author Topic: [help,urgently] arduio programing problem  (Read 950 times)
0 Members and 1 Guest are viewing this topic.
Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4771
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A keyboard is from computer , that was a exam , and tomorrow i will do it for my examination .

You have much bigger problems than that exam.
1 day before the exam and you start to ask for help. You were sick before the project was assigned? Consider before you answer that no one here can save your exam. It is tomorrow already and you have a lifetime of tomorrows coming.

You don't have to 'look good' so why not 'be real' just because being real gives you a real chance to not have this happen to you again. Yah, it comes down to you and none of us here. Please help yourself, get the incomplete and come back ready to work your brains hard. It will do you a lot of good and when you learn, you 'look good'.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have we had "the dog ate my Arduino" excuse yet?
Logged

Per Arduino ad Astra

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@lloyddean,
Why are you using uint8_ts instead of byte?

Did my reply above answer your question adequately?
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 86
Posts: 3445
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@lloyddean,
Why are you using uint8_ts instead of byte?

Did my reply above answer your question adequately?

No, not really, well unless an uint8_t takes up less memory than a byte.
For anything being assigned to a pin, it should be a byte, it saves memory even if it is just one byte less. For anything that actually requires more memory usage like an int or long, signed or unsigned, fine, but a regular pin should be a byte.

I'm curious as to what the compiler makes a #define variable.
Edit: -_- iPhone spell check.
« Last Edit: May 10, 2013, 10:07:51 pm by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, it's not 'define'd, again referencing "Arduino.h"

Code:
typedef uint8_t byte;
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 93
Posts: 3968
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For anything being assigned to a pin, it should be a byte, it saves memory even if it is just one byte less. For anything that actually requires more memory usage like an int or long, signed or unsigned, fine, but a regular pin should be a byte.

I'm curious as to what the compiler makes a #define variable.

Short answer: None of the above.

Long answer: #define is a preprocessor directive, the compiler never sees it. #define does not define a variable. Given

Code:
#define identifier replacement

the preprocessor literally replaces each occurrence of identifier in the source code with replacement. Think of it as a text-based replacement like might be done with a word processor, e.g. replace every occurrence of foo with bar. The compiler gets the source code after the replacements occur.

Even longer answer: http://en.wikipedia.org/wiki/C_preprocessor#Macro_definition_and_expansion
« Last Edit: May 10, 2013, 10:18:21 pm by Jack Christensen » Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Queens, New York
Offline Offline
Faraday Member
**
Karma: 86
Posts: 3445
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so if you just write "#define ledpin 13" representing pin 13, is it an int, uint8_t, byte... I know it replaces whatever you put, but what about numbers, what does it make them, and how much memory do they use up?
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the macro itself the '13' is an integer literal but what happens with the integer literal depends upon the context in which it is expanded.

The main thing here is that the question had NOTHING to do with 'define'.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12568
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what about numbers, what does it make them, and how much memory do they use up?

The behaviour is defined - I think it's defined by the language spec, but if not then it's defined by GCC. As far as I remember it, integer literals without any explicit type are of type int unless they are too big to be represented as an int, in which case they are of type long int. If the value is used in an expression, it can also be promoted to the type required to evaluate that expression (e.g. an int value used in an expression where a float is required would be implicitly promoted to a float).
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: 1 [2]   Go Up
Jump to: