写出在 16X16 LED 点阵显示屏上,上排8×16 点阵由左向右滚动显示字符串“CTBU MCU Final Test”(包含空格),下排8×16 点阵则由右向左滚动显示自己姓名的拼音全部和学 号。要求两个相反方向以平滑、适当的速度移动字符,循环显示。不能是反白显示。的代码

时间: 2024-02-21 15:57:21 浏览: 20
以下是一种基于 Arduino 平台的代码实现: ``` #include <LedControl.h> // 引入 LED 点阵控制库 // 定义 LED 点阵控制器的引脚 const int DIN_PIN = 12; const int CS_PIN = 11; const int CLK_PIN = 10; // 定义 LED 点阵的行列数 const int ROWS = 8; const int COLS = 16; // 定义上下两行的字符串 char upperRow[] = " CTBU MCU Final Test "; char lowerRow[] = "zhangsan 2021000000"; // 创建 LED 点阵控制对象 LedControl lc = LedControl(DIN_PIN, CLK_PIN, CS_PIN, 1); void setup() { // 初始化 LED 点阵控制器 lc.shutdown(0, false); // 关闭低功耗模式 lc.setIntensity(0, 8); // 设置亮度 lc.clearDisplay(0); // 清空显示内容 } void loop() { // 上行从左向右滚动 for (int i = 0; i < strlen(upperRow) - COLS + 1; i++) { // 从字符串中截取一列,并将其转换为二进制数值 byte colData = 0; for (int j = 0; j < ROWS; j++) { if (upperRow[i + j] != ' ') { // 空格不显示 colData |= 1 << j; } } // 在 LED 点阵上显示一列数据 for (int k = 0; k < COLS; k++) { lc.setColumn(0, k, colData); delay(50); // 控制移动速度 } } // 下行从右向左滚动 for (int i = strlen(lowerRow) - COLS; i >= 0; i--) { // 从字符串中截取一列,并将其转换为二进制数值 byte colData = 0; for (int j = 0; j < ROWS; j++) { if (lowerRow[i + j] != ' ') { // 空格不显示 colData |= 1 << j; } } // 在 LED 点阵上显示一列数据 for (int k = COLS - 1; k >= 0; k--) { lc.setColumn(0, k, colData); delay(50); // 控制移动速度 } } } ``` 需要注意的是,这是一种简单的实现方式,难免会有一些细节需要根据实际情况进行调整。另外,代码中使用了 LedControl 库来控制 LED 点阵,如果使用其他的控制方式可能需要修改部分代码。

相关推荐

解释下列代码#include <iostream> #include <string> using namespace std; class Date { public: Date(int year, int month, int day) : year_(year), month_(month), day_(day) {}; friend ostream& operator<<(ostream& os, const Date& date) { os << date.year_ << "-" << date.month_ << "-" << date.day_; return os; } private: int year_; int month_; int day_; }; class Person { public: Person(const string& name, const Date& birthday) : name_(name), birthday_(birthday) {}; virtual ~Person() {}; protected: string name_; Date birthday_; }; class Teacher : public Person { public: Teacher(const string& id, const string& name, const Date& birthday, const string& major, const string& affiliation) : Person(name, birthday), id_(id), major_(major), affiliation_(affiliation) {}; void PrintInfo() const { cout << "Name: " << name_ << endl; cout << "Birthday: " << birthday_ << endl; cout << "Teacher ID: " << id_ << endl; cout << "Teaching Major: " << major_ << endl; cout << "Affiliation: " << affiliation_ << endl; cout << "The basic information: " << id_ << ' ' << name_ << ' ' << birthday_ << ' ' << major_ << ' ' << affiliation_ << endl; } private: string id_; string major_; string affiliation_; }; class Student : public Person { public: Student(const string& id, const string& name, int score, const Date& birthday) : Person(name, birthday), id_(id), score_(score) {}; void PrintInfo() const { cout << "Name: " << name_ << endl; cout << "Birthday: " << birthday_ << endl; cout << "Student ID: " << id_ << endl; cout << "Student Score: " << score_ << endl; cout << "The basic information: " << id_ << ' ' << name_ << ' ' << score_ << endl; cout << birthday_ << endl; } private: string id_; int score_; }; int main() { Date student_birthday(1976, 5, 27); //修改学生出生日期 Student student("2023007", "kxiong", 92, student_birthday); student.PrintInfo(); Date teacher_birthday(1998, 1, 7); //修改教师出生日期 Teacher teacher("20210058", "xsong", teacher_birthday, "Computer Science", "CTBu"); teacher.PrintInfo(); return 0; }

最新推荐

recommend-type

基于三层感知机实现手写数字识别-内含源码和说明书.zip

基于三层感知机实现手写数字识别-内含源码和说明书.zip
recommend-type

setuptools-40.7.0.zip

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

搭建VGG16神经网络实现图像分类-内含源码和说明书.zip

搭建VGG16神经网络实现图像分类-内含源码和说明书.zip
recommend-type

setuptools-40.6.1.zip

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

华为OD机试D卷 - 判断字符串子序列 - 免费看解析和代码.html

私信博主免费获取真题解析以及代码
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用 Python 画一个可以动的爱心

好的,我可以帮助您使用Python来绘制一个动态的爱心。您可以使用turtle库来实现。以下是实现代码: ```python import turtle import math # 设置画布和画笔 canvas = turtle.Screen() canvas.bgcolor("black") pencil = turtle.Turtle() pencil.speed(0) pencil.color("red", "pink") pencil.pensize(3) # 定义爱心函数 def draw_love(heart_size, x_offset=0, y_offset=0):
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。