Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on an Arduino powered Tetris game. To keep track of the pieces that have fallen and become fixed I have an array of bytes

byte theGrid[] = {   
B00000000,
B00000000,  
B00000000,
B00000000,
B00000000,
...

This works great when the well is only 8 LEDs wide, but I need it to be 16 wide. Is there a way to perform bitwise operations on a 16 bit number, like a short? I tried just declaring theGrid as a short, but I'm getting this error no matter what I do.

tetris:62: error: 'B0000000000000000' was not declared in this scope

The reason I was using byte is so I could use bitread and bitset. So if an L piece comes down and lands, I can bitset the appropriate bits like this

bitSet(theGrid[pixelY], 15-pixelX); 

and end up with

B1000000000000000, B1110000000000000
share|improve this question
    
There are no bitwise operations in that code. – Ignacio Vazquez-Abrams Dec 6 '14 at 19:07
    
@IgnacioVazquez-Abrams I edited the OP – ddickson1 Dec 6 '14 at 19:11
up vote 3 down vote accepted

The main problem that you're having is that binary literals don't exist in C; the Arduino libraries get around this by having every single binary value from 1'b0 to 8'b1111_1111 defined as a macro in cores/arduino/binary.h. The obvious workaround is to use octal, decimal, or hexadecimal literals instead.

unsigned short theGrid[] = {
00,
0,
0x0,
 ...
};

Bitwise operations work as normal.

theGrid[pixelY] |= _BV(15 - pixelX);
share|improve this answer
    
Thanks, I got a similar answer on stackoverflow. I think this will work :) – ddickson1 Dec 6 '14 at 19:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.