关于流水灯的问题,新手求教
本帖最后由 gwzyou 于 2019-8-17 22:48 编辑C:\Users\asus\Pictures\Camera Roll
怎样使最右边的灯在左边有灯移动时常亮?
希望各位能看懂我的意思 8个灯
1111 1110
0111 1110 左边的灯右移直至右边第二个,右边第一个一直亮着
结果:11111100
类推:01111100
1111 1000
这种叫沉积流水灯,每次移动到头后保留状态,与新移动的流水相或即可。 神奇 发表于 2019-8-18 23:56
这种叫沉积流水灯,每次移动到头后保留状态,与新移动的流水相或即可。
哦哦,谢谢,请问有没有相关的程序代码呢,能不能发来看看 可以,有数组法和直接移位法,私聊找我。 新手不知道咋写,用数组写一个了
#include "reg52.h"
#include "intrins.h"
#define led P2
typedef unsigned char u8;
typedef unsigned int u16;
u8 code duan={
{0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe},
{0x7e,0xbe,0xde,0xee,0xf6,0xfa,0xfc},
{0x7c,0xbc,0xdc,0xec,0xf4,0xf8},
{0x78,0xb8,0xd8,0xe8,0xf0},
{0x70,0xb0,0xd0,0xe0},
{0x60,0xa0,0xc0},
{0x40,0x80},
{0x00}
};
void delay(u16 i)
{
while(i--);
}
void main()
{
while(1)
{
u8 i,j;
led=0xff;
for(i=0;i<8;i++)
{
for(j=0;j<8-i;j++)
{
led=duan;
delay(50000);
}
}
}
}
页:
[1]