This site is both a personal blog and my knowledge management page. I regularly archive some of my personal study notes and only display a few recent projects on the homepage.
本站既是个人博客,也是我的知识管理页面。我会定期归档一些个人学习笔记,仅在主页展示少数近期项目。
If you are not familiar with the directory of this site, you can refer to the tree diagram below or press Ctrl+K to search and quickly locate the article you need:
代码如下:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <math.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const float PHI = (1.0 + sqrt(5.0)) / 2.0;
const float SCALE = 12.0;
float vertices[20][3] = {
{-1, -1, -1},
{-1, -1, 1},
{-1, 1, -1},
{-1, 1, 1},
{1, -1, -1},
{1, -1, 1},
{1, 1, -1},
{1, 1, 1},
{0, -1 / PHI, -PHI},
{0, -1 / PHI, PHI},
{0, 1 / PHI, -PHI},
{0, 1 / PHI, PHI},
{-1 / PHI, -PHI, 0},
{-1 / PHI, PHI, 0},
{1 / PHI, -PHI, 0},
{1 / PHI, PHI, 0},
{-PHI, 0, -1 / PHI},
{PHI, 0, -1 / PHI},
{-PHI, 0, 1 / PHI},
{PHI, 0, 1 / PHI}};
int edges[30][2];
int edgeCount = 0;
float angleX = 0.0;
float angleY = 0.0;
float angleZ = 0.0;
float dist2(float *a, float *b)
{
return (a[0] - b[0]) * (a[0] - b[0]) +
(a[1] - b[1]) * (a[1] - b[1]) +
(a[2] - b[2]) * (a[2] - b[2]);
}
void generateEdges()
{
float threshold = 3.0;
edgeCount = 0;
for (int i = 0; i < 20; i++)
{
for (int j = i + 1; j < 20; j++)
{
float d = dist2(vertices[i], vertices[j]);
if (d < threshold)
{
if (edgeCount < 30)
{
edges[edgeCount][0] = i;
edges[edgeCount][1] = j;
edgeCount++;
}
}
}
}
}
void drawDodecahedron()
{
int projected[20][2];
for (int i = 0; i < 20; i++)
{
float x = vertices[i][0] * SCALE;
float y = vertices[i][1] * SCALE;
float z = vertices[i][2] * SCALE;
float y1 = y * cos(angleX) - z * sin(angleX);
float z1 = y * sin(angleX) + z * cos(angleX);
float x2 = x * cos(angleY) + z1 * sin(angleY);
float z2 = -x * sin(angleY) + z1 * cos(angleY);
float x3 = x2 * cos(angleZ) - y1 * sin(angleZ);
float y3 = x2 * sin(angleZ) + y1 * cos(angleZ);
float distance = 50.0;
float factor = distance / (distance + z2);
int px = (int)(x3 * factor + SCREEN_WIDTH / 2);
int py = (int)(y3 * factor + SCREEN_HEIGHT / 2);
projected[i][0] = px;
projected[i][1] = py;
}
for (int e = 0; e < edgeCount; e++)
{
int p1 = edges[e][0];
int p2 = edges[e][1];
display.drawLine(projected[p1][0], projected[p1][1],
projected[p2][0], projected[p2][1],
SSD1306_WHITE);
}
}
void setup()
{
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS))
{
for (;;)
;
}
display.clearDisplay();
generateEdges();
}
void loop()
{
display.clearDisplay();
drawDodecahedron();
display.display();
angleX += 0.02;
angleY += 0.03;
angleZ += 0.015;
delay(40);
}
实验目的
了解时钟的基本原理,利用定时器做到每隔一秒产生一次中断,在屏幕上显示计数+1,实现简单秒表功能。并且通过按钮接入外部时钟,用定时器的方式实现手动计数器。
原理
定时器其实就是计数器。STM32有三种:高级、通用和基本定时器,从前到后包含后者全部功能。其中高级定时器在APB2外设总线,性能更强。另两个都在APB1总线。
基本定时器
基本定时器只有定时中断和主模式触发DAC:

实验目的
了解外部中断的原理、作用并熟悉其c语言实现。本次实验做一个简易计数器,当按下按键时计数器的值+1,并实时显示在oled屏上。
实验过程
硬件部分
如图接线:

硬件部分
本次实验使用esp32c3 super mini开发板和0.96寸双色oled屏,按图接线:

注意供电接3v3不要接5v。
软件部分
如果用Arduino控制,需要额外安装三个适配SSD1306芯片的驱动库:Adafruit SSD1306 - v2.4.0
、Adafruit GFX Library - v1.12.1
、Adafruit BusIO - v1.17.4
,可以直接打开PIO Home -> Liararies搜索安装。
前言
概述
本项目实现了一个最最基本的Web蓝牙应用:网页端可以用按钮控制开发板上LED灯的亮灭。这个功能看似简单,实际上它具备了一个物联网系统的所有功能:通过Web网页控制蓝牙设备,无论多复杂的物联网蓝牙系统都是这样,只是多加了一些服务功能而已。
思路
大致做法是控制设备(本项目中是开着网页的电脑)启动一个蓝牙信道连接到被控设备(本项目中的开发板)。之后,控制设备可以通过这个信道把数据传给被控设备。
按一下按钮,传过去一个0x01,被控设备通过回调接收,收到以后就把GPIO设为高电平,就是开灯;相反传0x00就设为低电平,关灯。当然,被控设备也可以向控制设备反馈,即完成GPIO切换后把是否成功和当前状态发给前端。
Rust是无GC的语言
Rust 不需要一个在程序运行时定期扫描内存并自动回收垃圾的机制(即垃圾回收器,Garbage Collector)。它通过一套独特的所有权(Ownership)系统,在编译期就严格规定了谁拥有内存、谁有权限修改、以及内存何时应该被释放。这套规则由编译器检查,确保了内存安全,而无需运行时 GC 的介入。
系统资源都被唯一绑定在某一个变量身上,出了作用域直接销毁,开发者无需手动调用free()
(像在 C/C++ 中那样),也无需依赖 GC 来寻找并清理垃圾,这样一来它的运行速度就可以做到巨快无比(因为抛掉了GC),作为系统语言它比C/C++都要快得多。
Preface
The author claimed that there's few Catholic have actually read the Bible, and he explained why:
There are lots of historical reasons for this Catholic state of affairs in the
middle of the twentieth century. The church had an exaggerated fear of
private interpretation of the Bible. Couldn’t reading one’s own Bible lead to
all sorts of false understanding? Better to let the church teach us what we
needed to know.

前期准备
为了跑通这个项目,需要准备三个文件夹:
📁root
├─ 📁ballrobot20240702
├─ 📁cvi_media_src-main
└─ 📁rvnano_webrtc_streamer-master