这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » 【炫Q键盘】JB板灯效开发教程(同样适用于keng板),不需回复全可见

共16条 1/2 1 2 跳转至

【炫Q键盘】JB板灯效开发教程(同样适用于keng板),不需回复全可见

专家
2015-12-13 09:50:45     打赏


专家
2015-12-13 09:51:06     打赏
2楼

二楼放一些技术资料


专家
2015-12-13 09:51:57     打赏
3楼

最简单的全灯亮,主要用于测试烧写程序,灯是否焊对方向,是否有问题灯,默认caps灯不亮,效果如下


专家
2015-12-13 10:00:12     打赏
4楼

JB_01代码,全灯

#include <SPI.h>
void setup() {
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  pinMode (10, OUTPUT);
  digitalWrite(8, HIGH);
  SPI.begin();
  digitalWrite(10, LOW);
  SPI.transfer(0xff); 
  SPI.transfer(0x00); 
  SPI.transfer(0x00); 
  digitalWrite(10, HIGH);
  digitalWrite(9, LOW);
  delay(100);
}
void loop() {
  delay(100);  
}

 


专家
2015-12-13 10:08:12     打赏
5楼

弱光,大概10%的亮度,采用高速硬件PWM所以不闪,关键代码,0x1f代表亮度,0x00-0xff,非线性关系

  analogWrite(9, (byte)(0xff-0x1f));


专家
2015-12-13 10:09:08     打赏
6楼

JB_02代码,弱光

#include <SPI.h>
void setup() {
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  pinMode (10, OUTPUT);
  digitalWrite(8, HIGH);
  SPI.begin();
  digitalWrite(10, LOW);
  SPI.transfer(0xff); 
  SPI.transfer(0x00); 
  SPI.transfer(0x00); 
  digitalWrite(10, HIGH);
  analogWrite(9, (byte)(0xff-0x1f));
  delay(100);
}
void loop() {
  delay(100);  
}

 


专家
2015-12-13 10:14:45     打赏
7楼

单点亮第一步,源自141的创意,点亮WASD几个方向键,主要思路反复进行第二行和第三行的扫描


专家
2015-12-13 10:15:54     打赏
8楼

JB_03代码,对于全透键帽太刺眼了,建议参考02调光代码改进

#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() {
  digitalWrite(10, LOW);
  SPI.transfer(0x02); 
  SPI.transfer(0xff); 
  SPI.transfer(0xff-0x04); 
  digitalWrite(10, HIGH);
  delay(1);  
  digitalWrite(10, LOW);
  SPI.transfer(0x04); 
  SPI.transfer(0xff); 
  SPI.transfer(0xff-0x0E); 
  digitalWrite(10, HIGH);
  delay(1);  
}

 


专家
2015-12-13 10:25:23     打赏
9楼

老段子,让灯光动起来,简单流水效果,同样支持调光,调速,可自行发挥


专家
2015-12-13 10:26:41     打赏
10楼

JB_04代码,简单流水灯

#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;  
  for(i=1;i<256;i*=2)  
  {  
    digitalWrite(10, LOW);  
    SPI.transfer(0xff);   
    SPI.transfer(0xff);   
    SPI.transfer((byte)(0xff-i));   
    digitalWrite(10, HIGH);  
    delay(50);    
  }  
  for(i=1;i<256;i*=2)  
  {  
    digitalWrite(10, LOW);  
    SPI.transfer(0xff);   
    SPI.transfer((byte)(0xff-i));   
    SPI.transfer(0xff);   
    digitalWrite(10, HIGH);  
    delay(50);    
  }  
}  

 


共16条 1/2 1 2 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]