por Iddar Olivares / @iddar
Descarga el codigo de la practia desde aquí
'use strict'
const Five = require('johnny-five')
const board = new Five.Board({repl: false})
board.on('ready', () => {
.......
.......
.......
})
'use strict'
const Five = require('johnny-five')
const board = new Five.Board({repl: false})
board.on('ready', () => {
let devices = {}
devices.lcd = new Five.LCD({
controller: 'JHD1313M1'
})
callback(null, devices)
})
'use strict'
const Five = require('johnny-five')
const board = new Five.Board({repl: false})
function setup (callback) {
board.on('ready', () => {
let devices = {}
devices.lcd = new Five.LCD({
controller: 'JHD1313M1'
})
callback(null, devices)
})
}
module.exports = setup
'use strict'
const express = require('express')
const app = express()
const http = require('http').Server(app)
const path = require('path')
function server (config) {
const PORT = process.env.PORT || config.PORT
const pub = path.resolve(__dirname, '..', 'public')
app.use(express.static(pub))
http.listen(PORT, () => {
console.log('http://localhost:' + PORT)
})
return http
}
module.exports = server
'use strict'
const SocketIo = require('socket.io')
function socketServer (server, callback) {
const io = SocketIo(server)
io.on('connection', (socket) => {
console.log('Socket.io Ok')
callback(socket)
})
}
module.exports = socketServer
'use strict'
const onStartSocket = (devices, socket) => {
socket.on('text', (message) => {
devices.lcd.clear().print(message)
})
socket.on('color', (rgbColor) => {
devices.lcd.bgColor(rgbColor.r, rgbColor.g, rgbColor.b)
})
}
module.exports = onStartSocket
body>
body>
body {
display: flex;
align-items: center;
flex-direction: column;
background: #bababa;
}
.form {
flex: 1;
display: flex;
align-items: center;
height: 100vh;
}
......
'use strict'
const socket = io.connect(window.location.origin)
const inputs = document.getElementsByTagName('input')
const text = inputs[0]
const color = inputs[1]
const debounceInput = _.debounce((event) => {
const value = event.target.value
socket.emit('text', _.deburr(value))
console.log(value)
}, 150)
const debounceColor = _.debounce((event) => {
const value = event.target.value
socket.emit('color', hexToRgb(value))
console.log(hexToRgb(value))
}, 25)
text.focus()
text.addEventListener('input', debounceInput)
color.addEventListener('input', debounceColor)
http://github.com/iddar/slides
Descarga el codigo de la practia desde aquí