星光璀璨,采用数组和随机数,让键盘灯随机扇动
JB_05代码,星光璀璨
#include <SPI.h> byte keymap[70] = {0}; void setup() { pinMode (8, OUTPUT); pinMode (9, OUTPUT); pinMode (10, OUTPUT); digitalWrite(8, HIGH); SPI.begin(); delay(100); digitalWrite(9, LOW); } byte j=0; void loop() { byte l=0; int i=0; for(int k=0;k<5;k++) { int k2=0xff-((keymap[l++]>i)<<0)-((keymap[l++]>i)<<1)-((keymap[l++]>i)<<2)-((keymap[l++]>i)<<3)-((keymap[l++]>i)<<4)-((keymap[l++]>i)<<5)-((keymap[l++]>i)<<6); int k1=0xff-((keymap[l++]>i)<<0)-((keymap[l++]>i)<<1)-((keymap[l++]>i)<<2)-((keymap[l++]>i)<<3)-((keymap[l++]>i)<<4)-((keymap[l++]>i)<<5)-((keymap[l++]>i)<<6); digitalWrite(10, LOW); SPI.transfer(1<<k); SPI.transfer(k1); SPI.transfer(k2); digitalWrite(10, HIGH); delay(1); } j+=32; if (j==0) { for(int k=0;k<70;k++) if (keymap[k]>0) keymap[k]-=16; keymap[random(70)]=64; } }
JB_06代码,多行流水灯
#include <SPI.h> void setup() { pinMode (8, OUTPUT); pinMode (9, OUTPUT); pinMode (10, OUTPUT); digitalWrite(8, HIGH); SPI.begin(); digitalWrite(10, LOW); SPI.transfer(0x00); SPI.transfer(0xff); SPI.transfer(0xff); digitalWrite(10, HIGH); digitalWrite(9, LOW); delay(100); } void loop() { int i,j; for(j=1;j<16;j*=2) { for(i=1;i<128;i*=2) { digitalWrite(10, LOW); SPI.transfer(j); SPI.transfer(0xff); SPI.transfer((byte)(0xff-i)); digitalWrite(10, HIGH); delay(50); } for(i=1;i<128;i*=2) { digitalWrite(10, LOW); SPI.transfer(j); SPI.transfer((byte)(0xff-i)); SPI.transfer(0xff); digitalWrite(10, HIGH); delay(50); } } }
有奖活动 | |
---|---|
【有奖活动——B站互动赢积分】活动开启啦! | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |