新建
This commit is contained in:
parent
76069b4e19
commit
4423091627
120
.gitignore
vendored
120
.gitignore
vendored
@ -1,3 +1,123 @@
|
||||
# ---> Node
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
.env.production
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# ---> Python
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
17
hello.py
17
hello.py
@ -1,17 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import time
|
||||
import sys
|
||||
from sense_hat import SenseHat
|
||||
sense = SenseHat()
|
||||
red = (100, 0, 0)
|
||||
blue = (0, 0, 100)
|
||||
|
||||
try:
|
||||
while True:
|
||||
sense.show_message("What\'d you like?", 0.1, red)
|
||||
sense.show_message("Hot dog, please.", 0.1, blue)
|
||||
sense.show_message("Here you are.", 0.1, red)
|
||||
sense.show_message("Thank you.", 0.1, blue)
|
||||
except KeyboardInterrupt:
|
||||
sense.clear()
|
||||
sys.exit()
|
40
index.js
Normal file
40
index.js
Normal file
@ -0,0 +1,40 @@
|
||||
const express = require('express')
|
||||
const socketio = require('socket.io')
|
||||
const sense = require('sense-hat-led').sync
|
||||
const app = express()
|
||||
const server = app.listen(3000, '0.0.0.0', () => console.log('server is running'))
|
||||
const io = socketio(server)
|
||||
app.use(express.static('public'))
|
||||
sense.setRotation(180)
|
||||
sense.lowLight = true
|
||||
flash()
|
||||
io.on('connection', (client) => {
|
||||
client.on('action', ({ action, x, y }) => {
|
||||
console.log({ action, x, y })
|
||||
switch (action) {
|
||||
case 'on':
|
||||
sense.setPixel(Number(x), Number(y), [50, 50, 100])
|
||||
break
|
||||
case 'off':
|
||||
sense.setPixel(Number(x), Number(y), [0, 0, 0])
|
||||
break
|
||||
case 'hello':
|
||||
sense.flashMessage('HELLO', 1, [50, 50, 100])
|
||||
sense.clear()
|
||||
break
|
||||
case 'flash':
|
||||
flash()
|
||||
break
|
||||
case 'clear':
|
||||
sense.clear()
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
function flash() {
|
||||
sense.clear([50, 50, 255])
|
||||
setTimeout(sense.clear, 10)
|
||||
}
|
2568
package-lock.json
generated
Normal file
2568
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
27
package.json
Normal file
27
package.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "my-sense-hat",
|
||||
"version": "0.1.0",
|
||||
"description": "我的树莓派SenseHat",
|
||||
"main": "sensehat.js",
|
||||
"scripts": {
|
||||
"start": "nodemon",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "ssh://git@nas:2222/zhaoxin/my-sense-hat.git"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Zhao Xin <7176466@qq.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"easyimage": "^3.1.1",
|
||||
"express": "^4.18.1",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"sense-hat-led": "^1.2.0",
|
||||
"socket.io": "^4.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.19"
|
||||
}
|
||||
}
|
159
public/index.html
Normal file
159
public/index.html
Normal file
@ -0,0 +1,159 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="shortcut icon" href="data:" type="image/x-icon">
|
||||
<title>Sense Hat</title>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
#matrix {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
width: 94px;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.led {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border: 1px solid gray;
|
||||
background-color: whitesmoke;
|
||||
cursor: pointer;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.led.on {
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
button {
|
||||
width: 94px;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="matrix">
|
||||
<div class="row">
|
||||
<div class="led" data-y="0" data-x="0" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="0" data-x="1" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="0" data-x="2" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="0" data-x="3" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="0" data-x="4" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="0" data-x="5" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="0" data-x="6" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="0" data-x="7" onclick="turnon(event)"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="led" data-y="1" data-x="0" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="1" data-x="1" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="1" data-x="2" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="1" data-x="3" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="1" data-x="4" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="1" data-x="5" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="1" data-x="6" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="1" data-x="7" onclick="turnon(event)"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="led" data-y="2" data-x="0" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="2" data-x="1" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="2" data-x="2" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="2" data-x="3" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="2" data-x="4" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="2" data-x="5" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="2" data-x="6" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="2" data-x="7" onclick="turnon(event)"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="led" data-y="3" data-x="0" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="3" data-x="1" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="3" data-x="2" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="3" data-x="3" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="3" data-x="4" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="3" data-x="5" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="3" data-x="6" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="3" data-x="7" onclick="turnon(event)"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="led" data-y="4" data-x="0" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="4" data-x="1" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="4" data-x="2" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="4" data-x="3" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="4" data-x="4" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="4" data-x="5" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="4" data-x="6" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="4" data-x="7" onclick="turnon(event)"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="led" data-y="5" data-x="0" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="5" data-x="1" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="5" data-x="2" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="5" data-x="3" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="5" data-x="4" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="5" data-x="5" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="5" data-x="6" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="5" data-x="7" onclick="turnon(event)"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="led" data-y="6" data-x="0" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="6" data-x="1" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="6" data-x="2" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="6" data-x="3" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="6" data-x="4" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="6" data-x="5" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="6" data-x="6" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="6" data-x="7" onclick="turnon(event)"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="led" data-y="7" data-x="0" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="7" data-x="1" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="7" data-x="2" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="7" data-x="3" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="7" data-x="4" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="7" data-x="5" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="7" data-x="6" onclick="turnon(event)"></div>
|
||||
<div class="led" data-y="7" data-x="7" onclick="turnon(event)"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="button" data-action="clear">clear all</button>
|
||||
<br>
|
||||
<button class="button" data-action="hello">hello</button>
|
||||
<br>
|
||||
<button class="button" data-action="flash">flash</button>
|
||||
<br>
|
||||
<button class="button" data-action="temp">temp</button>
|
||||
|
||||
<script src="socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
const client = io()
|
||||
document.addEventListener('click', (event) => {
|
||||
const item = event.target
|
||||
if (item.classList.contains('led')) {
|
||||
item.classList.toggle('on')
|
||||
const { x, y } = item.dataset
|
||||
const action = item.classList.contains('on') ? 'on' : 'off'
|
||||
client.emit('action', { action, x, y })
|
||||
} else if (item.classList.contains('button')) {
|
||||
const { action } = item.dataset
|
||||
document.querySelectorAll('.led').forEach((led) => led.classList.remove('on'))
|
||||
client.emit('action', { action })
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
11
python/helloworld.py
Normal file
11
python/helloworld.py
Normal file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
import time
|
||||
import sys
|
||||
from sense_hat import SenseHat
|
||||
sense = SenseHat()
|
||||
try:
|
||||
while True:
|
||||
sense.show_message("Hello, World!", 0.1, (0, 0, 100))
|
||||
except KeyboardInterrupt:
|
||||
sense.clear()
|
||||
sys.exit()
|
0
sensehat.js
Normal file
0
sensehat.js
Normal file
Loading…
Reference in New Issue
Block a user