Go Down

Topic: Need Help in PROGMEM. (Read 773 times) previous topic - next topic

maskinao


#define MASK(n)  (0x80 >> n)


i got a little bit confused about this. how can this be done? and is "uint8_t" same as unsigned int? haven't used that before.

thanks for the reply! :) i'll go check it out.
Don't stop Learning.

Arduino Projects:

SMS-Based LED Matrix Display
http://youtu.be/WVhDr5CNxwE

tack

#6
Dec 16, 2012, 05:53 pm Last Edit: Dec 16, 2012, 05:56 pm by tack Reason: 1
In Arduno an int or unsigned int is 16 bits, the equivalent to int16_t or uint16_t accordingly.

An int (int16_t) can store -32767 to +32767. An unsigned int (uint16_t) can store 0 to 65535.

If you only need to store 0 to 255 then you can save 8 bits of memory by declaring more accurately as uint8_t as an 8 bit unsigned integer. If you need -127 to +127 then you can declare as int8_t.

It can help save some memory when you only have a couple of KB to play in.

robtillaart

(0x80 >> n)  => read  - http://arduino.cc/en/Reference/Bitshift -


A quick look makes me think this is the only place where the mask is used so you can replace it
Code: [Select]

void Display (void)                    // display the data to the LED Matrix
{
 int i = 0;
 for (i = 7; i >=0 ; i--)
 {
   mask = 0x80 >> i ;
   scan();
   digitalWrite(pins[i],LOW);         // pin ON
   for(d=0;d<INTEN;d++){}
   digitalWrite(pins[i],HIGH);        // pin OFF
 }
}


Quote
and is "uint8_t" same as unsigned int?

uint8_t is an unsigned int of 8 bits a.k.a. byte
unsigned int is a unsigned int of 16 bits == uint16_t
There is also unsigned long  == uint32_t
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

maskinao


(0x80 >> n)  => read  - http://arduino.cc/en/Reference/Bitshift -


A quick look makes me think this is the only place where the mask is used so you can replace it
Code: [Select]

void Display (void)                    // display the data to the LED Matrix
{
 int i = 0;
 for (i = 7; i >=0 ; i--)
 {
   mask = 0x80 >> i ;
   scan();
   digitalWrite(pins[i],LOW);         // pin ON
   for(d=0;d<INTEN;d++){}
   digitalWrite(pins[i],HIGH);        // pin OFF
 }
}


i tried this out and it actually made the program larger. hehe. I'll edit out my ints with uint8_t. :) hopefully it would make the code smaller. thanks again!
Don't stop Learning.

Arduino Projects:

SMS-Based LED Matrix Display
http://youtu.be/WVhDr5CNxwE

PeterH


Code: [Select]

   for(d=0;d<INTEN;d++){}



This doesn't look right. Am I missing something?
I only provide help via the forum - please do not contact me for private consultancy.

Go Up