Go Down

Topic: [help,urgently] arduio programing problem (Read 1 time) previous topic - next topic

GoForSmoke


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

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Groove

Have we had "the dog ate my Arduino" excuse yet?
Per Arduino ad Astra

lloyddean


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


Did my reply above answer your question adequately?

HazardsMind

#18
May 11, 2013, 04:51 am Last Edit: May 11, 2013, 05:07 am by HazardsMind Reason: 1


@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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

lloyddean

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

Code: [Select]

typedef uint8_t byte;

Jack Christensen

#20
May 11, 2013, 05:15 am Last Edit: May 11, 2013, 05:18 am by Jack Christensen Reason: 1

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: [Select]
#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
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

HazardsMind

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?
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

lloyddean

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

PeterH


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).
I only provide help via the forum - please do not contact me for private consultancy.

Go Up