极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10640|回复: 0

电位器控制和自动的LED Matrix

[复制链接]
发表于 2013-10-21 22:51:04 | 显示全部楼层 |阅读模式
参考了以下内容:
@yangqiang29 的《MAX7219芯片驱动8*8点阵》
http://www.geek-workshop.com/thread-3665-1-1.html
@迷你强 的《Arduino入门教程--第六课--电位器PWM控制LED亮度 》
http://www.geek-workshop.com/thread-1113-1-1.html
Arduino网站的电位器操作
http://arduino.cc/en/tutorial/potentiometer
Arduino网站的条件判断
http://arduino.cc/en/Reference/Else
8*8点阵设计
http://www.pial.net/tools/


昨晚参考Yangqiang29的帖子,实现了LED Matrix的显示和切换,最后做了一个不停旋转的“电风扇”,今晚改了改,使用电位器控制“转动”。




代码如下:
#include <LedControl.h>
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
第一个参数:pin 12 is connected to the DataIn
第二个参数:pin 11 is connected to the CLK
第三个参数:pin 10 is connected to LOAD
第四个参数:We have only a single MAX72XX.
*/

int exchange=6;
int val;
LedControl lc=LedControl(exchange,11,10.1);
unsigned long delaytime=100;
unsigned long delaytime1=200;

void setup(){
  pinMode(exchange,OUTPUT);
  lc.shutdown(0,false);
  lc.setIntensity(0,4);
  lc.clearDisplay(0);
  Serial.begin(9600);
  
}
void ledled(){
int val=analogRead(A0);
Serial.println(val);
byte one[8]={B10000001,
B01000010,
B00100100,
B00011000,
B00011000,
B00100100,
B01000010,
B10000001};
byte two[8]={B01000000,
B00100001,
B00010010,
B00011100,
B00111000,
B01001000,
B10000100,
B00000010};
byte three[8]={B00010000,
B00010000,
B00010000,
B00011111,
B11111000,
B00001000,
B00001000,
B00001000};
byte four[8]={B00001000,
B00001000,
B00001000,
B11111000,
B00011111,
B00010000,
B00010000,
B00010000};
byte five[8]={B00000010,
B10000100,
B01001000,
B00111000,
B00011100,
B00010010,
B00100001,
B01000000};
if(val<400 || val>1000){
lc.setRow(0,0,one[0]);
lc.setRow(0,1,one[1]);
lc.setRow(0,2,one[2]);
lc.setRow(0,3,one[3]);
lc.setRow(0,4,one[4]);
lc.setRow(0,5,one[5]);
lc.setRow(0,6,one[6]);
lc.setRow(0,7,one[7]);
}
else if(val<600){
lc.setRow(0,0,two[0]);
lc.setRow(0,1,two[1]);
lc.setRow(0,2,two[2]);
lc.setRow(0,3,two[3]);
lc.setRow(0,4,two[4]);
lc.setRow(0,5,two[5]);
lc.setRow(0,6,two[6]);
lc.setRow(0,7,two[7]);
}
else if(val<800){
lc.setRow(0,0,three[0]);
lc.setRow(0,1,three[1]);
lc.setRow(0,2,three[2]);
lc.setRow(0,3,three[3]);
lc.setRow(0,4,three[4]);
lc.setRow(0,5,three[5]);
lc.setRow(0,6,three[6]);
lc.setRow(0,7,three[7]);
}
else if(val<900){
lc.setRow(0,0,four[0]);
lc.setRow(0,1,four[1]);
lc.setRow(0,2,four[2]);
lc.setRow(0,3,four[3]);
lc.setRow(0,4,four[4]);
lc.setRow(0,5,four[5]);
lc.setRow(0,6,four[6]);
lc.setRow(0,7,four[7]);
}
else{
lc.setRow(0,0,five[0]);
lc.setRow(0,1,five[1]);
lc.setRow(0,2,five[2]);
lc.setRow(0,3,five[3]);
lc.setRow(0,4,five[4]);
lc.setRow(0,5,five[5]);
lc.setRow(0,6,five[6]);
lc.setRow(0,7,five[7]);
}
}
void loop(){
ledled();
delay(500);
}

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-8 21:42 , Processed in 0.037567 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表