Hi I have a somewhat basic question, but I wanted to know how different data types affects my program.
I modified the basic Arduino 'Blink' sketch, to what I think is rather optimizing it, but I'm not sure my logic behind it is correct.
Here is the code I made:
/*This code will turn pin 13 into an output, and
* make an led attached to it blink.
*/
// VARAIBLES
const byte pin13=13; // This sets varaible name 'pin13' = pin 13
/*
1. Data type 'byte' ranges stored values 0-54, consumes on 1 byte, while 'int' consumes 2
Data type 'int' rangees stored values -32,768 to 32,767, consumes
2 bytes. This is too large to use for pins when memory is limited on a board
2. The compiler used by the IDE, avr-gcc, knows that
a 'const' variable will be left out of RAM since
this variable cannot be changed
*/
void setup()
{
// initialize digital pin 13 as an output.
pinMode(pin13, OUTPUT);
}
void loop()
{
digitalWrite(pin13, HIGH);
delay(1000);
digitalWrite(pin13, LOW);
delay(1000);
}
Here are my questions:
- Does using 'byte' really save memory? When I changed my code from:
'const byte pin13 = 13'
to
' const int pin13 = 13',
the compiler still said that I was using 928 bytes of program storage space. I excepted that the with 'int' I'd instead use 929 bytes.
- If I use an int = 32000, or int = 23, do both of these value each use 2 bytes of data?