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[] = {   

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
  • 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

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[] = {

Bitwise operations work as normal.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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