Go to Post If that many teams could do it successfully every match this year I will eat my robot. - Jay O'Donnell [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 10-02-2011, 15:09
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Better bitwise conversion

Hello,

I am working on a program to control an arduino from a ds, and I have this code that converts all of the button input bools to a byte.

Code:
				//pack buttons into a byte
				if(keysHeld() & KEY_A) {
				    amount += 1;
				} else if (keysHeld() & KEY_B) {
				    amount += 2;
				} else if (keysHeld() & KEY_Y) {
				    amount += 4;
				} else if (keysHeld() & KEY_X) {
				    amount += 8;
				} else if (keysHeld() & KEY_L) {
				    amount += 16;
				} else if (keysHeld() & KEY_R) {
				    amount += 32;
				} else if (keysHeld() & KEY_START) {
				    amount += 64;
				} else if (keysHeld() & KEY_SELECT) {
				    amount += 128;
				} else {
				    amount = 0;
				}
amount is a byte.

How can i do this more elegantly?
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 14:47.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi