- complétement refactorisé la branche LED RG
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
-- Scripts de seconde chance pour réparer une boucle dans le restart
|
||||
|
||||
print("\n repair.lua zf181119.1511 \n")
|
||||
print("\n repair.lua zf181120.1012 \n")
|
||||
|
||||
--if file.exists("wifi_ap_start.lua") then dofile("wifi_ap_start.lua") end
|
||||
if file.exists("wifi_ap_stop.lua") then dofile("wifi_ap_stop.lua") end
|
||||
if file.exists("wifi_cli_conf.lua") then dofile("wifi_cli_conf.lua") end
|
||||
if file.exists("wifi_cli_start.lua") then dofile("wifi_cli_start.lua") end
|
||||
if file.exists("ide2.lua") then dofile("ide2.lua") end
|
||||
if file.exists("ide.lua") then dofile("ide.lua") end
|
||||
if file.exists("telnet_srv.lua") then dofile("telnet_srv.lua") end
|
||||
|
||||
jobtimer1=tmr.create()
|
||||
|
||||
64
LED_RGB_WS2812/tests effects/a_test_train.lua
Normal file
64
LED_RGB_WS2812/tests effects/a_test_train.lua
Normal file
@@ -0,0 +1,64 @@
|
||||
-- Scripts juste pour tester des effets à la mano
|
||||
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
|
||||
-- roue des couleurs: https://iro.js.org/?ref=oldsite
|
||||
|
||||
print("\n a_tst_train.lua zf181125.1258 \n")
|
||||
|
||||
print("Initializing LED strip...")
|
||||
ws2812.init()
|
||||
buffer = ws2812.newBuffer(30, 3)
|
||||
buffer:fill(0, 0, 0)
|
||||
ws2812.write(buffer)
|
||||
print("done.")
|
||||
print()
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
|
||||
print("toto")
|
||||
|
||||
ws2812.init()
|
||||
strip_buffer = ws2812.newBuffer(300, 3)
|
||||
ws2812_effects.init(strip_buffer)
|
||||
-- initially all leds off
|
||||
ws2812_effects.set_speed(255)
|
||||
ws2812_effects.set_brightness(0)
|
||||
ws2812_effects.set_color(0,0,0)
|
||||
ws2812_effects.start()
|
||||
print("done.")
|
||||
print()
|
||||
|
||||
ws2812.init()
|
||||
|
||||
local i, buffer = 0, ws2812.newBuffer(300, 3)
|
||||
buffer:fill(0, 0, 0, 0)
|
||||
|
||||
exit
|
||||
|
||||
|
||||
ws2812.init()
|
||||
j=1
|
||||
local i, buffer = 0, ws2812.newBuffer(300, 3); buffer:fill(0, 0, 0, 0); tmr.create():alarm(20, 1, function()
|
||||
i = i + j
|
||||
buffer:fade(2)
|
||||
buffer:set(i % buffer:size() + 1, 255, 255, 255)
|
||||
ws2812.write(buffer)
|
||||
if i>=buffer:size()-1 or i<=0 then
|
||||
j=j*-1
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
|
||||
ws2812.write(string.char(255, 0, 0, 0, 255, 0, 0, 0, 255)) -- RGB positionnement naturel
|
||||
|
||||
ws2812.write(string.char(0, 255, 0, 0, 0, 255, 255, 0, 0, 255, 0, 255, 255, 255, 0, 0, 255, 255)) -- GBR and CMY en GBR WS2813!
|
||||
|
||||
ws2812.write(string.char(0, 255, 0, 0, 0, 255/3, 255, 0, 0, 255, 0, 255, 255, 255, 0, 0, 255, 255)) -- vert compensé GBR and CMY en GBR WS2813!
|
||||
|
||||
ws2812.write(string.char(128, 255, 128, 200, 200, 255, 255, 200, 200, 255, 255, 255, 40, 40, 40, 5, 5, 5)) -- White RGB & White 100/50/10%
|
||||
|
||||
ws2812.write(string.char(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) -- LED OFF
|
||||
]]
|
||||
79
LED_RGB_WS2812/tests effects/wip/a_test_fill.lua
Normal file
79
LED_RGB_WS2812/tests effects/wip/a_test_fill.lua
Normal file
@@ -0,0 +1,79 @@
|
||||
-- Scripts juste pour tester des effets à la mano
|
||||
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
|
||||
-- roue des couleurs: https://iro.js.org/?ref=oldsite
|
||||
|
||||
print("\n a_tst_train.lua zf181125.1258 \n")
|
||||
|
||||
znbled=300
|
||||
|
||||
function RGB_clear()
|
||||
ws2812.init()
|
||||
buffer = ws2812.newBuffer(znbled, 3)
|
||||
buffer:fill(0, 0, 0)
|
||||
ws2812.write(buffer)
|
||||
end
|
||||
|
||||
print("Initializing LED strip...")
|
||||
RGB_clear()
|
||||
print("done.")
|
||||
|
||||
|
||||
znbled_tst=10
|
||||
zlumino=1 --luminosité 0 <> 1
|
||||
zR=255*zlumino
|
||||
zG=255*zlumino
|
||||
zB=255*zlumino
|
||||
buffer = ws2812.newBuffer(znbled_tst, 3)
|
||||
buffer:fill(0, 0, 255) -- Green, Red , Blue
|
||||
ws2812.write(buffer)
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
|
||||
print("toto")
|
||||
|
||||
ws2812.init()
|
||||
strip_buffer = ws2812.newBuffer(300, 3)
|
||||
ws2812_effects.init(strip_buffer)
|
||||
-- initially all leds off
|
||||
ws2812_effects.set_speed(255)
|
||||
ws2812_effects.set_brightness(0)
|
||||
ws2812_effects.set_color(0,0,0)
|
||||
ws2812_effects.start()
|
||||
print("done.")
|
||||
print()
|
||||
|
||||
ws2812.init()
|
||||
|
||||
local i, buffer = 0, ws2812.newBuffer(300, 3)
|
||||
buffer:fill(0, 0, 0, 0)
|
||||
|
||||
exit
|
||||
|
||||
|
||||
ws2812.init()
|
||||
j=1
|
||||
local i, buffer = 0, ws2812.newBuffer(300, 3); buffer:fill(0, 0, 0, 0); tmr.create():alarm(20, 1, function()
|
||||
i = i + j
|
||||
buffer:fade(2)
|
||||
buffer:set(i % buffer:size() + 1, 255, 255, 255)
|
||||
ws2812.write(buffer)
|
||||
if i>=buffer:size()-1 or i<=0 then
|
||||
j=j*-1
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
|
||||
ws2812.write(string.char(255, 0, 0, 0, 255, 0, 0, 0, 255)) -- RGB positionnement naturel
|
||||
|
||||
ws2812.write(string.char(0, 255, 0, 0, 0, 255, 255, 0, 0, 255, 0, 255, 255, 255, 0, 0, 255, 255)) -- GBR and CMY en GBR WS2813!
|
||||
|
||||
ws2812.write(string.char(0, 255, 0, 0, 0, 255/3, 255, 0, 0, 255, 0, 255, 255, 255, 0, 0, 255, 255)) -- vert compensé GBR and CMY en GBR WS2813!
|
||||
|
||||
ws2812.write(string.char(128, 255, 128, 200, 200, 255, 255, 200, 200, 255, 255, 255, 40, 40, 40, 5, 5, 5)) -- White RGB & White 100/50/10%
|
||||
|
||||
ws2812.write(string.char(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) -- LED OFF
|
||||
]]
|
||||
17
LED_RGB_WS2812/tests effects/wip/blink_led2.lua
Normal file
17
LED_RGB_WS2812/tests effects/wip/blink_led2.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
-- programme pour faire clignoter une LED version simplifiée
|
||||
|
||||
print("\n blink_led2.lua zf181015.1138 \n")
|
||||
|
||||
zLED=0
|
||||
gpio.mode(zLED, gpio.OUTPUT)
|
||||
ztmr_LED = tmr.create()
|
||||
value = true
|
||||
|
||||
tmr.alarm(ztmr_LED, 100, tmr.ALARM_AUTO, function ()
|
||||
if value then
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
else
|
||||
gpio.write(zLED, gpio.LOW)
|
||||
end
|
||||
value = not value
|
||||
end)
|
||||
32
LED_RGB_WS2812/tests effects/wip/boot.lua
Normal file
32
LED_RGB_WS2812/tests effects/wip/boot.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
-- Scripts à charger après le boot pour démarrer son appli
|
||||
|
||||
print("\n boot.lua zf181125.1234 \n")
|
||||
|
||||
--f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "telnet_srv.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
--f= "test_train.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
x_dsleep=7 y_dsleep=30 dsleep()
|
||||
|
||||
i=1
|
||||
jobtimer1=tmr.create()
|
||||
tmr.alarm(jobtimer1, 1*1000, tmr.ALARM_AUTO, function()
|
||||
print(i) i=i+1
|
||||
if wifi.sta.getip() ~= nil then
|
||||
tmr.stop(jobtimer1)
|
||||
tmr.stop(ztmr_SLEEP)
|
||||
x_dsleep=300 y_dsleep=30 dsleep()
|
||||
print("c'est connecté...")
|
||||
end
|
||||
end)
|
||||
]]
|
||||
|
||||
19
LED_RGB_WS2812/tests effects/wip/initz.lua
Normal file
19
LED_RGB_WS2812/tests effects/wip/initz.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
--Script de bootstrap, test au moment du boot qui a été la cause de boot.
|
||||
-- Si la cause est un power on ou une connexion depuis l'IDE, alors
|
||||
-- le script repair.lua pendant 30 secondes avant de continuer
|
||||
--Source: https://nodemcu.readthedocs.io/en/master/en/modules/node/#nodebootreason
|
||||
|
||||
print("\n init.lua zf181120.0002 \n")
|
||||
|
||||
_, reset_reason = node.bootreason()
|
||||
print("reset_reason:",reset_reason)
|
||||
if reset_reason == 6 or reset_reason == 6 then
|
||||
print("seconde chance...")
|
||||
f= "repair.lua" if file.exists(f) then dofile(f) end
|
||||
initalarme=tmr.create()
|
||||
tmr.alarm(initalarme, 30*1000, tmr.ALARM_SINGLE, function()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
end)
|
||||
else
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
end
|
||||
11
LED_RGB_WS2812/tests effects/wip/repair.lua
Normal file
11
LED_RGB_WS2812/tests effects/wip/repair.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
-- Scripts de seconde chance pour réparer une boucle dans le restart
|
||||
|
||||
print("\n repair.lua zf181119.2356 \n")
|
||||
|
||||
f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) end
|
||||
f= "telnet_srv.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
jobtimer1=tmr.create()
|
||||
tmr.alarm(jobtimer1, 5*1000, tmr.ALARM_AUTO, function()
|
||||
print("repair...")
|
||||
end)
|
||||
Binary file not shown.
@@ -1,15 +0,0 @@
|
||||
|
||||
print()
|
||||
print("starting init.lua...")
|
||||
print()
|
||||
print("local files:")
|
||||
l=file.list()
|
||||
for k,v in pairs(l) do
|
||||
print(k.." "..v)
|
||||
end
|
||||
print()
|
||||
|
||||
print("starting webleds...")
|
||||
print()
|
||||
dofile('webleds.lua')
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>LED Strip Control</title>
|
||||
<style>
|
||||
|
||||
body {
|
||||
font-family: Bitstream Vera Sans, Verdana, Helvetica, Arial, sans-serif;
|
||||
font-size: 12px;
|
||||
background-color: #dddddd;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
/* this matches 'retina' displays */
|
||||
@media screen and (-webkit-min-device-pixel-ratio: 2) {
|
||||
body {
|
||||
font-size: 24px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 64px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 48px;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>LED strip control page</h1>
|
||||
|
||||
<h2>Choose an effect:</h2>
|
||||
<ul>
|
||||
<li><a href="/?set=effect&effect=rainbow_cycle">Rainbow Cycle</a></li>
|
||||
<li><a href="/?set=effect&effect=larson_scanner">Larson Scanner</a></li>
|
||||
<li><a href="/?set=effect&effect=fire">Fire</a></li>
|
||||
<li><a href="/?set=effect&effect=blink">Blink</a></li>
|
||||
<li><a href="/?set=effect&effect=circus_combustus">Circus Combustus</a></li>
|
||||
</ul>
|
||||
|
||||
<h2>Pick a color:</h2>
|
||||
<ul>
|
||||
<li><a href="/?set=color&r=255&g=0&b=0">Red</a></li>
|
||||
<li><a href="/?set=color&r=0&g=255&b=0">Green</a></li>
|
||||
<li><a href="/?set=color&r=0&g=0&b=255">Blue</a></li>
|
||||
<li><a href="/?set=color&r=255&g=255&b=255">White</a></li>
|
||||
<li><a href="/?set=color&r=0&g=0&b=0">Black</a></li>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
--Script de bootstrap, en appuyant sur le bouton ça démarre start_boot,
|
||||
-- autrement en attendant 8 secondes cela démarre start_boot
|
||||
|
||||
print("\n init.lua zf181017.1026\n")
|
||||
|
||||
zswitch=3 --switch flash
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
initalarme=tmr.create()
|
||||
|
||||
function hvbouton()
|
||||
gpio.trig(zswitch, "none")
|
||||
tmr.unregister(initalarme)
|
||||
dofile("start_boot.lua")
|
||||
-- dofile("start_job.lua")
|
||||
end
|
||||
|
||||
gpio.trig(zswitch, "both", hvbouton)
|
||||
|
||||
tmr.alarm(initalarme, 8000, tmr.ALARM_SINGLE, function()
|
||||
print("\nStart\n")
|
||||
dofile("start_boot.lua")
|
||||
-- dofile("start_job.lua")
|
||||
end)
|
||||
@@ -1,8 +0,0 @@
|
||||
-- Scripts à charger au moment du boot
|
||||
|
||||
print("\n start_boot.lua zf181105.1122 \n")
|
||||
|
||||
print("starting webleds...")
|
||||
print()
|
||||
dofile('webleds.lua')
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
-- initially based on https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_examples/webap_toggle_pin.lua
|
||||
|
||||
-- start wifi client or AP mode
|
||||
--dofile('wificlient.lua')
|
||||
dofile('wifiap.lua')
|
||||
|
||||
-- LED init (strip with 72 leds)
|
||||
print("Initializing LED strip...")
|
||||
ws2812.init()
|
||||
strip_buffer = ws2812.newBuffer(6, 3)
|
||||
ws2812_effects.init(strip_buffer)
|
||||
-- initially all leds off
|
||||
ws2812_effects.set_speed(200)
|
||||
ws2812_effects.set_brightness(0)
|
||||
ws2812_effects.set_color(0,0,0)
|
||||
ws2812_effects.start()
|
||||
print("done.")
|
||||
print()
|
||||
|
||||
-- helper functions
|
||||
-- send a file from memory to the client; max. line length = 1024 bytes!
|
||||
function send_file(client, filename)
|
||||
if file.open(filename, "r") then
|
||||
repeat
|
||||
local line=file.read('\n')
|
||||
if line then
|
||||
client:send(line)
|
||||
end
|
||||
until not line
|
||||
file.close()
|
||||
end
|
||||
end
|
||||
|
||||
-- web server
|
||||
srv = net.createServer(net.TCP)
|
||||
srv:listen(80, function(conn)
|
||||
conn:on("receive", function(client, request)
|
||||
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
|
||||
if (method == nil) then
|
||||
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP")
|
||||
end
|
||||
local _GET = {}
|
||||
if (vars ~= nil) then
|
||||
for k, v in string.gmatch(vars, "(%w+)=([a-z0-9_]+)&*") do
|
||||
_GET[k] = v
|
||||
end
|
||||
end
|
||||
if (_GET.set == "effect") then
|
||||
print("setting effect", _GET.effect)
|
||||
ws2812_effects.set_mode(_GET.effect)
|
||||
ws2812_effects.set_speed(200)
|
||||
ws2812_effects.set_brightness(50)
|
||||
ws2812_effects.start()
|
||||
end
|
||||
if (_GET.set == "color") then
|
||||
print("setting color (RGB)", _GET.r, _GET.g, _GET.b)
|
||||
ws2812_effects.set_color(_GET.g, _GET.r, _GET.b) -- obviously our strip is GRB and not RGB
|
||||
end
|
||||
send_file(client, 'index.html')
|
||||
end)
|
||||
conn:on("sent", function(c) c:close() end)
|
||||
end)
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
|
||||
-- set AP mode
|
||||
wifi.setmode(wifi.SOFTAP)
|
||||
wifi.ap.config({ ssid = "webleds", pwd = "12345678" })
|
||||
print("Started AP mode")
|
||||
|
||||
-- get and display our IP addr.
|
||||
tmr.alarm(0, 1000, 1, function()
|
||||
if wifi.ap.getip() == nil then
|
||||
print("Getting AP info...")
|
||||
else
|
||||
print('IP: ', wifi.ap.getip())
|
||||
tmr.stop(0)
|
||||
end
|
||||
end)
|
||||
|
||||
print()
|
||||
|
||||
Reference in New Issue
Block a user