gpt4 book ai didi

c - Pixy CMUCAM5 开源示例代码 模运算

转载 作者:行者123 更新时间:2023-11-30 15:21:10 26 4
gpt4 key购买 nike

我一直忙于 PIXYCAM 和 Arduino Uno,我从他们的网站下载了下面的代码。现在有一个(i%50)操作,我不知道它的作用是什么?有人可以帮我解释一下这部分代码吗?

    #include <SPI.h>
#include <Pixy.h>
Pixy pixy;
void setup()
{
Serial.begin(9600);
Serial.print(“Starting...\n”);
pixy.init();
}
void loop()
{
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
blocks = pixy.getBlocks();
if (blocks)
{
i++;
if (i%50==0)
{
sprintf(buf, “Detected %d:\n”, blocks);
Serial.print(buf);
for (j=0; j<blocks; j++)
{
sprintf(buf, “ block %d: “, j);
Serial.print(buf);
pixy.blocks[j].print();
}
}
}
}

最佳答案

当 i 是 50 的整数倍时,它执行 if 子句的内容,因此当 i = 50, 100, 150, ... 时表达式为 true

我对 PIXYCAM 一无所知,但代码似乎每隔一段时间就会打印一组 block ......

关于c - Pixy CMUCAM5 开源示例代码 模运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29644660/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com