Arduino 入门程序示例之一片 LED(2015-06-11)
概述
从点到线,从线到面。现在开始要来一片的 LED 了,一大波的 LED 正在到来!
示例程序
因为手头没有现成的模块,手头只有 595,所以这里每一个示例程序都是使用 74HC595 扩展 IO 口的。后面不多加备注了。
现成的模块还有其它专门的驱动芯片的,程序写起来就更简单了,要根据具体的驱动芯片来决定程序,这个程序不通用的哦。
点阵显示静止的心
别看到静止两个字,这里点阵可是动态扫描的哟。所以程序里不能有 delay() 等阻塞主函数的延时函数。
// ----------------------------------------------------------------------------
// LEDLattice.ino
//
// Created 2015-06-07
// By seesea <seesea2517#gmail#com>
//
// LED 点阵
// 使用两个 74HC595 驱动单色 LED 点阵
//
// ---------------------------------------------------------------------------- const unsigned char latchPin = ; // 595 的 ST_CP
const unsigned char clockPin = ; // 595 的 SH_CP
const unsigned char dataPin = ; // 595 的 DS #define SIZE 7 // 点阵的行列数 // 每一行的模值
const byte row[] =
{
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
}; // 心形的取模
const byte heart[] =
{
0xFF, 0x93, 0x6D, 0x7D, 0xBB, 0xD7, 0xEF, 0xFF
}; void setup ()
{
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
} void loop()
{
showArrPic(heart);
} // 显示数组所代表的图片
void showArrPic(const byte arr[])
{
for (unsigned char i = ; i < ; ++i)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, (byte) arr[i]);
shiftOut(dataPin, clockPin, LSBFIRST, (byte) row[i]);
digitalWrite(latchPin, HIGH);
}
} // 另一种方式显示数组所代表的图片
void showArrPic2(const byte arr[])
{
static unsigned char i = ; digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, arr[i]);
shiftOut(dataPin, clockPin, LSBFIRST, row[i]);
digitalWrite(latchPin, HIGH); if (++i >= SIZE)
i = ;
}
简单看看接线吧,没有现成的模块,都是手工现搭的,纯天然……不建议自己搭,麻烦耗时还容易出错。(偷懒只在 VCC 处接了一个限流电阻,效果也还过得去,不怕麻烦的同学可以多加几个 :D )
![]() |
飘落的心
没错,它动起来了,所以它是动态扫描的。好吧,前面的语句是错误的示范 :D
这个程序示范了一个位移动画。
// ----------------------------------------------------------------------------
// latticeDownHeart.ino
//
// Created 2015-06-07
// By seesea <seesea2517#gmail#com>
//
// 点阵动画:飘落的心
// 使用两个 74HC595 驱动单色 LED 点阵,显示一个向下飘落的心,展示位移动画
//
// ---------------------------------------------------------------------------- const unsigned char latchPin = ; // 595 的 ST_CP
const unsigned char clockPin = ; // 595 的 SH_CP
const unsigned char dataPin = ; // 595 的 DS const unsigned long delayMs = ; // 图像运动延时时间 #define SIZE 8 // 点阵的行列数 // 每一行的模值
const byte row[] =
{
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
}; // 心形的取模
const byte heart[] =
{
0xFF, 0x93, 0x6D, 0x7D, 0xBB, 0xD7, 0xEF, 0xFF
}; void setup ()
{
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
} void loop()
{
static char y = -;
static unsigned long lastTick = millis(); // 延时一定时间后,移动坐标
if (millis() - lastTick > delayMs)
{
++y;
lastTick = millis(); if (y > SIZE)
y = -;
} showArrPic(heart, , y);
} // 显示数组所代表的图片
// 以 (x, y) 为左上角起点位置,默认在 (0, 0) 位置显示
// 坐标系:
// +------>
// | x
// |
// v y
//
void showArrPic(const byte arr[], char x, char y)
{
for (char i = ; i < SIZE; ++i)
{
if (i + x < || i + x >= SIZE ||
i + y < || i + y >= SIZE)
{
continue;
} digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, (byte) arr[i + x]);
shiftOut(dataPin, clockPin, LSBFIRST, (byte) row[i + y]);
digitalWrite(latchPin, HIGH);
}
}
咦,手机拍下的效果还有拖影,将就点吧,意思到了就行:):
![]() |
走动的小人
这里演示了一个逐帧动画。
// ----------------------------------------------------------------------------
// LEDLattice.ino
//
// Created 2015-06-07
// By seesea <seesea2517#gmail#com>
//
// 点阵动画:人物走路的逐帧动画演示
// 使用两个 74HC595 驱动单色 LED 点阵
//
// ---------------------------------------------------------------------------- const unsigned char latchPin = ; // 595 的 ST_CP
const unsigned char clockPin = ; // 595 的 SH_CP
const unsigned char dataPin = ; // 595 的 DS const unsigned long frameDelayMs = ; #define FRAME_NUM 4 // 关键帧帧数
#define SIZE 8 // 点阵的行列数 // 每一行的模值
const byte row[] =
{
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
}; // 人物走路的关键帧的取模
const byte man[FRAME_NUM][SIZE] =
{
{0xE7,0xE7,0xFF,0xC3,0xC5,0xE7,0xDB,0xBD},
{0xE7,0xE7,0xFF,0xE7,0xE3,0xE7,0xEB,0xDB},
{0xE7,0xE7,0xFF,0xE7,0xE7,0xE7,0xE7,0xE7},
{0xE7,0xE7,0xFF,0xE7,0xE3,0xE7,0xEB,0xDB}
}; void setup ()
{
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
} void loop()
{
static unsigned long lastTick = millis();
static unsigned char frame = ; // 延时一帧时间后,进入下一帧
if (millis() - lastTick >= frameDelayMs)
{
lastTick = millis(); ++frame;
if (frame >= FRAME_NUM)
frame = ;
} showArrPic(man[frame]);
} // 显示数组所代表的图片
void showArrPic(const byte arr[])
{
for (unsigned char i = ; i < SIZE; ++i)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, (byte) arr[i]);
shiftOut(dataPin, clockPin, LSBFIRST, (byte) row[i]);
digitalWrite(latchPin, HIGH);
}
}
没有绘画天分,这全是手工点出来的点阵越看越不像,大家将就点吧:
![]() |
Arduino 入门程序示例之一片 LED(2015-06-11)的更多相关文章
- Arduino 入门程序示例之一个 LED(2015-06-11)
前言 答应了群主写一些示例程序,一直拖延拖延拖延唉.主要还是害怕在各大高手面前班门弄斧……(这也算是给拖延症找一个美好的理由吧),这几天终于下决心要写出来了,各位高手拍砖敬请轻拍啊. 示例程序 首先是 ...
- Arduino 入门程序示例之一排 LED(2015-06-11)
概述 最简单的一个 LED 的实验之后,自然是增加几个 LED,咱排成一排来玩吧.最后,再把一排的 LED 排成一个 8 字来玩——七段数码管. 示例程序 流水灯 第一个出场的肯定是经典的流水灯,也叫 ...
- Arduino 入门程序示例之直流电机(2015-06-15)
概述 演示直流电机的控制. 示例程序 PWM控制直流电机 略过控制电机转停的示例啦,有需要就把这里的 PWM 换成数字口输出 HIGH 或 LOW 就行了. // ------------------ ...
- arduino入门学习实现语音控制LED灯
需要的准备的硬件arduino+PC+麦克风实现语音命令控制LED灯的亮灭. 首先需要将写好的arduino程序烧录到arduino uno主板中,下面是代码如下: int val;//定义变量val ...
- 译文 [ROM][多国语言][2015.06.11] Lenovo S750 (MTK6589) - andrea_d86-lenovos750-4.2.2
************************************************** andrea_d86-lenovos750-4.2.2-150530 ************** ...
- 2015.06.11,技术,关于Matlab中的Jbtest检验
总体分布的正态性检验一般采取Jarque-Bera检验方法. 1. JBTest检验的定义: 在统计学中,Jarque-Bera检验是对样本数据是否具有符合正态分布的偏度和峰度的拟合优度的检验.该检验 ...
- Arduino 极速入门系列–1 点亮 LED
本篇内容为,使用 Arduino 点亮 LED 的做法示范.很简单的一个入门示范.我们让 LED 闪. 本篇使用到的工具和材料 Arduino Mini Pro 1 PCS Mini USB 数据线 ...
- Arduino入门学习
一直听到许多做物联网.智能家居的控制器使用的是Arduino,从师兄那里拿到了一块Arduino开发板,进行了一下午的学习,感觉这个适合小孩子们玩:) 废话少说,总结一下,便于以后可能会用得到.我主要 ...
- struts2入门程序
struts2入门程序 1.示例 搭建编程环境就先不说了,这里假设已经搭建好了编程环境,并且下好了strut2的jar包,接下来程序. 1.1 新建web项目 点击File->New->D ...
随机推荐
- oracle 中的select ...connect by prior ...start with 及(+)的用法
1.select ...connect by prior ...start with的用法: select ... from <tablename> where <condition ...
- Foundation Sorting: Shellsort
/* Shell Sorting. * Implemention history:. * 2013-09-15, Mars Fu, first version. */ /* [Shell Sortin ...
- [每日一题] 11gOCP 1z0-052 :2013-09-15 Enterprise Manager Support Workbench..................B9
转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/11715219 正确答案:ABD EnterpriseManger Support Work ...
- asp.net生成RSS
经常看到博客.还有很多网站中有RSS订阅,今天就来玩玩asp.net生成RSS,在网上查找了相关资料 发现just soso,如下: aspx <?xml version="1.0&q ...
- 安卓入门学习之Hello,world!
第二章 Hello,world! 本文同时发表至简书,不为什么,用他的MarkDown在线编辑爽得要哭. 注意:本章节所使用的开发工具为Eclipse 以Android编程权威指南作为学习书物 第一节 ...
- C#之简单选择排序
以排列INT数组为简单示范 namespace 简单选择排序 { class Program { static void SelectViod(int[] data) { ; i < data. ...
- Quiz 6a Question 7————An Introduction to Interactive Programming in Python
First, complete the following class definition: class BankAccount: def __init__(self, initial_bal ...
- Django问题汇总
Q1.运行python manage.py runserver后,出现如下错误(CentOS6.5x86,Python2.7.12,Django1.10): django.core.exception ...
- poj 1604 Just the Facts
/** 大意: 求n! 结果 从左到右 第一个非零数 跟 1150 差不多.. **/ #include <iostream> #include <cstdio> using ...
- IOS 隐藏键盘。
在View的UITextField中经常需要输入完文字后隐藏软键盘,要实现着一点要让View的Controller实现UITextFieldDelegate代理,然后编写相应的代码. #import ...


