有没有什么建议可以在C周期性地递减数组的方式 [英] Is there a way you can decrement an array in a periodic fashion in C
问题描述
我正在写一个code为一些在领导的节段1每五秒钟,以减少
在此刻我的实际code是这个
FiveSecDelay + = 1;
如果(FiveSecDelay == 100)
{
count2--; //递减COUNT2为(uint32_t的x = 0; X 4;; X ++)//分裂计数到各个单独数字
{
NEW_VALUE [X] = COUNT2%10;
COUNT2 = COUNT2 / 10;
}为(uint32_t的I = 0; I&下; 4;我+ +)
{Segment_Write(数字[I],NEW_VALUE [I]);将值分配给段
}
FiveSecDelay = 0;
}
使用程序器调用函数每毫秒的IM,理论上这应该工作为我所用同样的方法来分配一个值段,
什么情况是,我有8起始值,它应该有7,6,5,4等,直到0,但由于某种原因,从8变为42并保持有
我曾试图修复它,但都拿出短。
任何帮助将是巨大的。
感谢您
无效检查(){
静态int数组[] = {142}; //你为什么要使用一个数组吗?
(*数组) - ;
}诠释主(){
而(真)
{
检查();
usleep(5000); //近似
}
返回0;
}
i'm writing a code for a number on a led segement to decrease by 1 every five seconds
my actual code at the moment is this
FiveSecDelay+=1;
if (FiveSecDelay ==100)
{
count2--; //decrement count2
for (uint32_t x = 0; x < 4; x++) //split count to to individual digits
{
new_value[x] = count2 % 10;
count2 = count2 / 10;
}
for (uint32_t i = 0; i < 4; i++)
{
Segment_Write(Digit[i],new_value[i]); assign value to segments
}
FiveSecDelay =0;
}
im using a schedular to call a function every milisecond, in theory this supposed to work as i used the same technique to assign a value to the segments, what happens is that i have a starting value of 8, and it supposed to got 7,6,5,4 and so on till 0, but for some reason it goes from 8 to 42 and stays there
I had tried to fix it but have come up short.
Any help would be great
Thank you
void check() {
static int array[] = {142}; // why are you using an array here?
(*array)--;
}
int main() {
while(true)
{
check();
usleep(5000); // approximate
}
return 0;
}
这篇关于有没有什么建议可以在C周期性地递减数组的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!