blockly实现可视化积木编程esp32单片机嵌入式开发板模拟器代码
代码语言:html
所属分类:其他
代码描述:blockly实现可视化积木编程esp32单片机嵌入式开发板模拟器代码
代码标签: blockly 可视化 积木 编程 esp32 单片机 嵌入式 开发板 模拟器 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🔧 ESP32 积木编程模拟器</title>
<!-- Blockly CDN -->
<script src="https://unpkg.com/blockly/blockly_compressed.js"></script>
<script src="https://unpkg.com/blockly/blocks_compressed.js"></script>
<script src="https://unpkg.com/blockly/javascript_compressed.js"></script>
<script src="https://unpkg.com/blockly/msg/zh-hans.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
min-height: 100vh;
color: #fff;
}
/* 顶部导航 */
.header {
background: rgba(0,0,0,0.3);
padding: 12px 20px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid rgba(255,255,255,0.1);
}
.logo {
font-size: 22px;
font-weight: bold;
display: flex;
align-items: center;
gap: 10px;
}
.logo-icon {
width: 36px;
height: 36px;
background: linear-gradient(45deg, #00d4aa, #00a8cc);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
}
.header-controls {
display: flex;
gap: 10px;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
display: flex;
align-items: center;
gap: 6px;
}
.btn-run {
background: linear-gradient(45deg, #00d4aa, #00a8cc);
color: #fff;
}
.btn-run:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(0, 212, 170, 0.4);
}
.btn-run.running {
background: linear-gradient(45deg, #f44336, #e91e63);
}
.btn-upload {
background: linear-gradient(45deg, #ff9800, #ff5722);
color: #fff;
}
.btn-reset {
background: rgba(255,255,255,0.1);
color: #fff;
border: 1px solid rgba(255,255,255,0.2);
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* 主容器 */
.main-container {
display: flex;
height: calc(100vh - 65px);
}
/* 左侧 - Blockly区域 */
.blockly-section {
flex: 1;
display: flex;
flex-direction: column;
border-right: 1px solid rgba(255,255,255,0.1);
}
.section-header {
padding: 10px 15px;
background: rgba(0,0,0,0.2);
font-size: 14px;
font-weight: 600;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid rgba(255,255,255,0.1);
}
#blocklyDiv {
flex: 1;
background: #fff;
}
/* 右侧面板 */
.right-panel {
width: 420px;
display: flex;
flex-direction: column;
background: rgba(0,0,0,0.2);
}
/* ESP32 模拟器 */
.simulator-section {
padding: 15px;
border-bottom: 1px solid rgba(255,255,255,0.1);
}
.esp32-board {
background: linear-gradient(180deg, #1e3a5f, #0d2137);
border-radius: 12px;
padding: 20px;
position: relative;
border: 2px solid #2a5a8a;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.board-title {
text-align: center;
font-size: 12px;
color: #fff;
margin-bottom: 15px;
letter-spacing: 2px;
}
.chip {
width: 80px;
height: 80px;
background: #1a1a1a;
border-radius: 8px;
margin: 0 auto 15px;
display: flex;
align-items: center;
justify-content: center;
font-size: 10px;
color: #888;
border: 1px solid #333;
position: relative;
}
.chip::before {
content: '';
position: absolute;
top: 5px;
left: 5px;
right: 5px;
bottom: 5px;
border: 1px solid #444;
border-radius: 4px;
}
.chip-dot {
position: absolute;
top: 8px;
left: 8px;
width: 8px;
height: 8px;
background: #444;
border-radius: 50%;
}
/* GPIO 引脚 */
.gpio-container {
display: flex;
justify-content: space-between;
margin-top: 15px;
}
.gpio-side {
display: flex;
flex-direction: column;
gap: 4px;
}
.gpio-pin {
display: flex;
align-items: center;
gap: 6px;
font-size: 10px;
}
.gpio-side.right .gpio-pin {
flex-direction: row-reverse;
}
.pin-hole {
width: 14px;
height: 14px;
background: #c4a000;
border-radius: 50%;
border: 2px solid #8b7500;
transition: all 0.2s;
}
.pin-hole.high {
background: #00ff00;
box-shadow: 0 0 10px #00ff00;
}
.pin-hole.low {
background: #333;
}
.pin-hole.pwm {
background: #ff9800;
box-shadow: 0 0 8px #ff9800;
}
.pin-label {
color: #aaa;
min-width: 35px;
}
.gpio-side.right .pin-label {
text-align: right;
}
/* 组件区域 */
.components-area {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 12px;
margin-top: 15px;
}
.component {
background: rgba(255,255,255,0.05);
border-radius: 10px;
padding: 12px;
text-align: center;
}
.component-label {
font-size: 11px;
color: #888;
margin-bottom: 8px;
}
/* LED */
.led {
width: 24px;
height: 24px;
border-radius: 50%;
margin: 0 auto;
border: 2px solid #444;
transition: all 0.1s;
}
.led.red { background: #330000; border-color: #550000; }
.led.red.on { background: #ff0000; box-shadow: 0 0 20px #ff0000; }
.led.green { background: #003300; border-color: #005500; }
.led.green.on { background: #00ff00; box-shadow: 0 0 20px #00ff00; }
.led.blue { background: #000033; border-color: #000055; }
.led.blue.on { background: #0088ff; box-shadow: 0 0 20px #0088ff; }
.led.yellow { background: #333300; border-color: #555500; }
.led.yellow.on { background: #ffff00; box-shadow: 0 0 20px #ffff00; }
/* 按钮 */
.hw-button {
width: 40px;
height: 40px;
border-radius: 50%;
background: linear-gradient(180deg, #555, #333);
border: 3px solid #222;
margin: 0 auto;
cursor: pointer;
transition: all 0.1s;
display: flex;
align-items: center;
justify-content: center;
color: #888;.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0