Datatype Practices for Arduino Author: Alexander Brevig Contact: firstname.lastname@example.org
This resource is subject to personal preference, but is based upon what seems to be a general consencus
The number one concern on a µCU is size.
|unsigned char||1 byte|
|unsigned int||2 byte|
|unsigned long||4 byte|
|string||1 byte + x|
|array||1 byte + x|
Because all data needs to be stored, the selection of how to store data makes an impact on performance.
My general rule of thumb is 'select the smallest variable that are large enough, and make the datatype unsigned where suited'
I would never use an int to hold the digital pin on an Arduino. The int ranges from -32,768 to 32,767, and is clearly too large a container to store a number that never gets larger than 54.
The byte however is perfect. It ranges from 0 to 255, which is plenty of headroom.
|Part of AlphaBeta Resources.|
|Last Modified:||July 17, 2009, at 05:28 PM|