Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 在10个led显示屏上显示healthbar_C_Arduino_Binary - Fatal编程技术网

C 在10个led显示屏上显示healthbar

C 在10个led显示屏上显示healthbar,c,arduino,binary,C,Arduino,Binary,对于编程课程,我必须制作一个带有fubarino和10个led显示屏的小游戏。在游戏中的某一点上,我需要向玩家显示“healthbar”或分数。运行状况可以介于10和0之间。我用了这段代码 value = -1; //set 1 bit off per point lost for(int i = 10; i>points[playerNr]; i--){ value &= !(1<<(points[playerNr]-1)); } showVa

对于编程课程,我必须制作一个带有fubarino和10个led显示屏的小游戏。在游戏中的某一点上,我需要向玩家显示“healthbar”或分数。运行状况可以介于10和0之间。我用了这段代码

  value = -1;
//set 1 bit off per point lost
  for(int i = 10; i>points[playerNr]; i--){
    value &= !(1<<(points[playerNr]-1));
  }
  showValue(value);
value=-1;
//每丢失一点设置1位
对于(int i=10;i>点[playerr];i--){

值&=!(1您可以使用
,直接创建一个设置了“n个最低位”的整数,而不是循环清除位(1u抱歉,您能否详细说明一下,您的评论对我来说不是很清楚。您会怎么做(1u
u
表示未签名的
onliterals@Typhaon这不是一个变量,这是一个无符号后缀,用于使
1
具有类型
unsigned int
,而不是
int
。您可以使用
showValue((1u So value=0;value |=(1)替换整个
for
循环
// playerNr is either 0 or 1 for one player or 2 for both
void showPoints(int playerNr){
  bool both = false;
  //subtract one point from both players if playerNr == 2
  if(playerNr == 2){
    both = true;
    playerNr = 1;
  }
  points[playerNr]--;
  value = -1;
  //flash all lights to show that the points are going to be shown
  showValue(value);
  delay(50);
  //set 1 bit off per point lost
  for(int i = 10; i>points[playerNr]; i--){
    value &= !(1<<(points[playerNr]-1));
  }
  showValue(value);
  //game position is either 0 or 9
  pos = 9*playerNr;
  //ascend is true if playerNr is 0 and vice versa
  ascend = !playerNr;
  if(both){
    pointLost = 0;
  } else {
    pointLost = -1;
  }
  //reset the game if points are 0
  if(points[playerNr]==0){
    points[0] = 10;
    points[1] = 10;
    points[playerNr]++;
    pointLost = playerNr;
  }
  timer = 1000;
}