- complétement refactorisé la branche LED RG

This commit is contained in:
Christian Zufferey
2018-11-25 13:20:27 +01:00
parent c4aaeb3e82
commit c6f823d33a
32 changed files with 224 additions and 189 deletions

View 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
]]

View File

@@ -0,0 +1,23 @@
-- Scripts juste pour tester 3x LED RGB
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
-- roue des couleurs: https://iro.js.org/?ref=oldsite
print("\n just_test_3x.lua zf181106.0940 \n")
print("Initializing LED strip...")
ws2812.init()
ws2812_effects.stop()
strip_buffer = ws2812.newBuffer(3, 3)
ws2812.write(string.char(255, 0, 0, 0, 255, 0, 0, 0, 255)) -- RGB natural
ws2812.write(string.char(0, 255, 0, 0, 0, 255, 255, 0, 0)) -- GBR WS2813
ws2812.write(string.char(0, 255, 0, 255, 0, 0, 0, 0, 255)) -- GRB WS2812
ws2812.write(string.char(255, 0, 255, 255, 255, 0, 0, 255, 255)) -- CMY en GBR WS2813!
ws2812.write(string.char(255, 0, 255, 0, 255, 255, 255, 255, 0)) -- CMY en GRB WS2812!
ws2812.write(string.char(128, 255, 64, 255, 200, 200, 200, 200, 255))
ws2812.write(string.char(255, 255, 255, 40, 40, 40, 5, 5, 5))
ws2812.write(string.char(0, 0, 0, 0, 0, 0, 0, 0, 0))

View File

@@ -0,0 +1,21 @@
-- Scripts juste pour tester 6x LED RGB
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
-- roue des couleurs: https://iro.js.org/?ref=oldsite
print("\n just_test_3x.lua zf181106.1458 \n")
print("Initializing LED strip...")
ws2812.init()
ws2812_effects.stop()
strip_buffer = ws2812.newBuffer(6, 3)
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

View 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
]]

View 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)

View 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)
]]

View File

@@ -0,0 +1,17 @@
-- fonction cat() pour afficher le contenu d'un fichier dans la flash
print("\n cat.lua zf180826.1109 \n")
function cat(zfile)
print("\n"..zfile.."\n-------------------------------")
zfilei = file.open(zfile, "r")
i=1
zline=file.readline()
repeat
print(i..": "..string.sub(zline,1,string.len(zline)-1))
i=i+1 zline=file.readline()
until zline== nil
file.close(zfilei)
print("-------------------------------")
end

View File

@@ -0,0 +1,15 @@
-- fonction dir() pour afficher les fichiers dans la flash
print("\n dir.lua zf180826.1019 \n")
function dir()
print("\n-------------------------------")
l=file.list() i=0
for k,v in pairs(l) do
i=i+v
print(k..string.rep(" ",19-string.len(k)).." : "..v.." bytes")
end
print("-------------------------------")
print('\nUsed: '..i..' bytes\nusage: dofile("file.lua")\n')
end
dir()

View 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

View 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)

View File

@@ -0,0 +1,12 @@
-- pour effacer TOUS les fichiers qui se trouve dans la flash du NodeMCU
print("\n rm_files.lua zf180907.1511 \n")
l=file.list() i=0
for k,v in pairs(l) do
i=i+v
file.remove(k)
end
print("-------------------------------")
print("\nC'est tout effaced :-) \n")