Refactorisé dossiers et écrit l'effet pour le chapeau

* l'effet train3 est le shift décalé de deux buffers avec mix des deux
* refactorisé encore une fois les dossiers de LED RGB
This commit is contained in:
Christian Zufferey
2018-12-04 21:01:11 +01:00
parent e574727962
commit 7e956cf1d6
42 changed files with 875 additions and 95 deletions

Binary file not shown.

View File

@@ -0,0 +1,11 @@
# Chapeau LED's
Petit code pour faire un effet sympa pour un chapeau avec un ruban de 35x LED RGB WS2812
zf181204.1951

View File

@@ -0,0 +1,69 @@
-- Scripts juste pour tester l'effet train
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
-- roue des couleurs: https://iro.js.org/?ref=oldsite
print("\n a_chapeau_z.lua zf181204.2057 \n")
znbled=36
function RGB_clear()
ws2812.init()
buffer = ws2812.newBuffer(znbled, 3)
buffer:fill(0, 0, 0)
ws2812.write(buffer)
end
RGB_clear()
fadeLevel=3
train1_R=255
train1_G=0
train1_B=0
train2_R=255
train2_G=0
train2_B=0
-- Buffer Train 1
myLedStrip1 = ws2812.newBuffer(znbled, 3)
myLedStrip1:fill(0,0,0)
myLedStrip1:set(1, train1_G, train1_R, train1_B)
myLedStrip1:fade(fadeLevel)
myLedStrip1:set(2, train1_G, train1_R, train1_B)
myLedStrip1:fade(fadeLevel)
myLedStrip1:set(3, train1_G, train1_R, train1_B)
myLedStrip1:fade(fadeLevel)
myLedStrip1:set(4, train1_G, train1_R, train1_B)
ws2812.write(myLedStrip1)
-- Buffer Train 2
myLedStrip2 = ws2812.newBuffer(znbled, 3)
myLedStrip2:fill(0,0,0)
myLedStrip2:set(znbled, train2_G, train2_R, train2_B)
myLedStrip2:fade(fadeLevel)
myLedStrip2:set(znbled-1, train2_G, train2_R, train2_B)
myLedStrip2:fade(fadeLevel)
myLedStrip2:set(znbled-2, train2_G, train2_R, train2_B)
myLedStrip2:fade(fadeLevel)
myLedStrip2:set(znbled-3, train2_G, train2_R, train2_B)
ws2812.write(myLedStrip2)
-- Buffer Train Total
myLedStrip = ws2812.newBuffer(znbled, 3)
myLedStrip:mix(255, myLedStrip1, 255, myLedStrip2)
ws2812.write(myLedStrip)
-- Train move
zspeed=25
train2timer1=tmr.create()
tmr.alarm(train2timer1, zspeed, tmr.ALARM_AUTO, function()
myLedStrip1:shift(1, ws2812.SHIFT_CIRCULAR) -- direction →
myLedStrip2:shift(-1, ws2812.SHIFT_CIRCULAR) -- direction ←
myLedStrip:mix(255, myLedStrip1, 255, myLedStrip2) -- mix both train
ws2812.write(myLedStrip)
end)

View File

@@ -0,0 +1,19 @@
-- Scripts juste pour éteindre toutes les LED du ruban
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
-- roue des couleurs: https://iro.js.org/?ref=oldsite
print("\n az_init_led.lua zf181201.1751 \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.")

View File

@@ -0,0 +1,23 @@
-- Scripts à charger après le boot pour démarrer son appli
print("\n boot.lua zf181204.2059 \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= "az_init_led.lua" if file.exists(f) then dofile(f) end
f= "a_train3.lua" if file.exists(f) then dofile(f) end
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
boottimer1=tmr.create()
tmr.alarm(boottimer1, 1*1000, tmr.ALARM_AUTO, function()
xfois =2
blink_LED ()
end)

View File

@@ -0,0 +1,32 @@
-- programme pour faire clignoter x fois une LED avec un rapport on/off
print("\n flash_led_xfois.lua zf181204.1955 \n")
zLED=0
zTm_On_LED = 50 --> en ms
zTm_Off_LED = 100 --> en ms
nbfois = 0
gpio.write(zLED, gpio.HIGH)
gpio.mode(zLED, gpio.OUTPUT)
ztmr_Flash_LED = tmr.create()
function blink_LED ()
if nbfois >= xfois then
-- print(nbfois)
nbfois = 0
else
if gpio.read(zLED)==gpio.HIGH then
gpio.write(zLED, gpio.LOW)
tmr.alarm(ztmr_Flash_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED)
else
gpio.write(zLED, gpio.HIGH)
nbfois = nbfois+1
tmr.alarm(ztmr_Flash_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
end
end
end
xfois =2
blink_LED ()

View File

@@ -1,8 +1,8 @@
-- Scripts juste pour tester des effets à la mano
-- Scripts juste pour tester l'effet train
-- 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 zf181201.1146 \n")
print("\n a_train1.lua zf181204.2004 \n")
znbled=36

View File

@@ -0,0 +1,60 @@
<!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>

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

View File

@@ -0,0 +1,63 @@
-- 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)

View File

@@ -0,0 +1,14 @@
-- Démarre le WIFI en mode AP
print("\n wifi_ap_start.lua zf181119.2359 \n")
local zmodewifi=wifi.getmode()
if zmodewifi == wifi.NULLMODE then
print("WIFI mode AP only")
wifi.setmode(wifi.SOFTAP)
elseif zmodewifi == wifi.STATION then
print("WIFI mode AP+CLI")
wifi.setmode(wifi.STATIONAP)
end
wifi.ap.config({ ssid = "NodeMCU "..wifi.ap.getmac(), pwd = "12345678" })
f= "wifi_info.lua" if file.exists(f) then dofile(f) end

View File

@@ -0,0 +1,12 @@
-- Petit script pour obtenir l'adresse IP du NodeMCU connecté sur un AP Wifi
print("\n wifi_get_ip.lua zf181119.2318 \n")
wifitimer1=tmr.create()
tmr.alarm(wifitimer1, 1000, tmr.ALARM_AUTO , function()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
else
tmr.stop(wifitimer1)
f= "wifi_info.lua" if file.exists(f) then dofile(f) end
end
end)

View File

@@ -0,0 +1,31 @@
-- Petit script pour afficher les infos actuel du WIFI
print("\n wifi_info.lua zf181119.0014 \n")
local zmodewifi=wifi.getmode()
--wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP
if zmodewifi == wifi.NULLMODE then
print("WIFI OFF")
elseif zmodewifi == wifi.STATION then
print("WIFI mode CLI")
print("Connected IP:\n",wifi.sta.getip())
do
local sta_config=wifi.sta.getconfig(true)
print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false")))
end
elseif zmodewifi == wifi.SOFTAP then
print("WIFI mode AP")
print("AP MAC:\n",wifi.ap.getmac())
print("AP IP:\n",wifi.ap.getip())
print("AP Connect:\n",wifi.ap.getconfig())
elseif zmodewifi == wifi.STATIONAP then
print("WIFI mode CLI+AP")
print("Connected IP:\n",wifi.sta.getip())
do
local sta_config=wifi.sta.getconfig(true)
print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false")))
end
print("AP MAC: "..wifi.ap.getmac())
print("AP IP: "..wifi.ap.getip())
end

View File

@@ -0,0 +1,9 @@
-- Déconnecte le WIFI
print("\n wifi_off.lua zf180822.0959 \n")
wifi.setmode(wifi.NULLMODE)
--[[
print(wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP)
print(wifi.getmode())
]]

View File

@@ -0,0 +1,31 @@
--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 xx secondes avant de continuer
--Source: https://nodemcu.readthedocs.io/en/master/en/modules/node/#nodebootreason
print("\n init.lua zf181125.1428 \n")
function second_chance()
print("seconde chance...")
f= "repair.lua" if file.exists(f) then dofile(f) end
initalarme=tmr.create()
tmr.alarm(initalarme, 8*1000, tmr.ALARM_SINGLE, function()
f= "boot.lua" if file.exists(f) then dofile(f) end
end)
end
_, reset_reason = node.bootreason()
print("reset_reason:",reset_reason)
if reset_reason == 0 then
print("power on")
second_chance()
elseif reset_reason == 4 then
print("node.restart")
f= "boot.lua" if file.exists(f) then dofile(f) end
elseif reset_reason == 6 then
print("reset")
second_chance()
else
print("autre raison")
end

View File

@@ -0,0 +1,16 @@
-- 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
f= "az_init_led.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,13 @@
# Gurilande effects
Tests fait pour ma guirlande du balcon pour Noël
Problème, j'ai 5 mètres de ruban avec 300 LED RGB et quand je les allume tous à fond, le courant n'arrive pas à arriver au bout du ruban.
Il faut donc jouer sur la puissance des LED et l'écartement, c'est à dire allumer que une sur deux ou trois.
zf181201.1153

View File

@@ -0,0 +1,40 @@
-- Scripts effet guirlande de Noël pour le balcon
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
-- roue des couleurs: https://iro.js.org/?ref=oldsite
print("\n a_guirlande.lua zf181201.1146 \n")
znbled=300
zstep=3
zpower=0.8
function RGB_clear()
ws2812.init()
buffer = ws2812.newBuffer(znbled, 3)
buffer:fill(0, 0, 0)
ws2812.write(buffer)
end
RGB_clear()
for i=1, znbled, zstep do
buffer:set(i, 123*zpower, 124*zpower, 125*zpower)
end
ws2812.write(buffer)
a={}
a=buffer:get(1)
print(buffer:get(1))
print(a)
a={}
a[0]=123
a[1]=124
a[2]=125
print(a[0],a[1],a[2])

View File

@@ -0,0 +1,19 @@
-- Scripts juste pour éteindre toutes les LED du ruban
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
-- roue des couleurs: https://iro.js.org/?ref=oldsite
print("\n az_init_led.lua zf181201.1751 \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.")

View File

@@ -0,0 +1,33 @@
-- Scripts à charger après le boot pour démarrer son appli
print("\n boot.lua zf181125.1635 \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= "a_test_train.lua" if file.exists(f) then dofile(f) end
--f= "a_test_fill.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,31 @@
--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 xx secondes avant de continuer
--Source: https://nodemcu.readthedocs.io/en/master/en/modules/node/#nodebootreason
print("\n init.lua zf181125.1428 \n")
function second_chance()
print("seconde chance...")
f= "repair.lua" if file.exists(f) then dofile(f) end
initalarme=tmr.create()
tmr.alarm(initalarme, 8*1000, tmr.ALARM_SINGLE, function()
f= "boot.lua" if file.exists(f) then dofile(f) end
end)
end
_, reset_reason = node.bootreason()
print("reset_reason:",reset_reason)
if reset_reason == 0 then
print("power on")
second_chance()
elseif reset_reason == 4 then
print("node.restart")
f= "boot.lua" if file.exists(f) then dofile(f) end
elseif reset_reason == 6 then
print("reset")
second_chance()
else
print("autre raison")
end

View File

@@ -0,0 +1,30 @@
-- 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_fill.lua zf181125.1632 \n")
znbled=300
function RGB_clear()
ws2812.init()
buffer = ws2812.newBuffer(znbled, 3)
buffer:fill(0, 0, 0)
ws2812.write(buffer)
end
function RGB_fill(nbled, Red, Green, Blue)
buffer = ws2812.newBuffer(nbled, 3)
buffer:fill(Green, Red, Blue) -- Green, Red , Blue
ws2812.write(buffer)
end
RGB_clear()
RGB_clear() ; RGB_fill(100, 255, 0, 0)
RGB_clear() ; RGB_fill(100, 0, 255, 0)
RGB_clear() ; RGB_fill(100, 0, 0, 255)
RGB_clear() ; l=0.10 ; R=l*(255) ; G=l*(80*0.99) ; B=l*(0*0.99) ; RGB_fill(300, R, G, B)

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,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 zf181125.1340 \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, 8*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,16 @@
-- 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
f= "az_init_led.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")

View File

@@ -0,0 +1,40 @@
-- Scripts effet guirlande de Noël pour le balcon
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
-- roue des couleurs: https://iro.js.org/?ref=oldsite
print("\n a_guirlande.lua zf181201.1146 \n")
znbled=300
zstep=3
zpower=0.8
function RGB_clear()
ws2812.init()
buffer = ws2812.newBuffer(znbled, 3)
buffer:fill(0, 0, 0)
ws2812.write(buffer)
end
RGB_clear()
for i=1, znbled, zstep do
buffer:set(i, 123*zpower, 124*zpower, 125*zpower)
end
ws2812.write(buffer)
a={}
a=buffer:get(1)
print(buffer:get(1))
print(a)
a={}
a[0]=123
a[1]=124
a[2]=125
print(a[0],a[1],a[2])

View File

@@ -1,8 +1,8 @@
-- Scripts juste pour tester des effets à la mano
-- Scripts juste pour éteindre toutes les LED du ruban
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
-- roue des couleurs: https://iro.js.org/?ref=oldsite
print("\n az_init_led.lua zf181125.1333 \n")
print("\n az_init_led.lua zf181201.1751 \n")
znbled=300
@@ -17,65 +17,3 @@ print("Initializing LED strip...")
RGB_clear()
print("done.")
--[[
znbled_tst=60
zlumino=1 --luminosité 0 <> 1
zR=255*zlumino
zG=255*zlumino
zB=255*zlumino
buffer = ws2812.newBuffer(znbled_tst, 3)
buffer:fill(zG, zR, zB) -- 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,30 @@
-- 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_fill.lua zf181125.1632 \n")
znbled=300
function RGB_clear()
ws2812.init()
buffer = ws2812.newBuffer(znbled, 3)
buffer:fill(0, 0, 0)
ws2812.write(buffer)
end
function RGB_fill(nbled, Red, Green, Blue)
buffer = ws2812.newBuffer(nbled, 3)
buffer:fill(Green, Red, Blue) -- Green, Red , Blue
ws2812.write(buffer)
end
RGB_clear()
RGB_clear() ; RGB_fill(100, 255, 0, 0)
RGB_clear() ; RGB_fill(100, 0, 255, 0)
RGB_clear() ; RGB_fill(100, 0, 0, 255)
RGB_clear() ; l=0.10 ; R=l*(255) ; G=l*(80*0.99) ; B=l*(0*0.99) ; RGB_fill(300, R, G, B)

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,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 zf181125.1340 \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, 8*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

@@ -1,29 +0,0 @@
-- 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 zf181201.1146 \n")
znbled=36
function RGB_clear()
ws2812.init()
buffer = ws2812.newBuffer(znbled, 3)
buffer:fill(0, 0, 0)
ws2812.write(buffer)
end
RGB_clear()
j=1
local i, buffer = 0, ws2812.newBuffer(znbled, 3); buffer:fill(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)

View File

@@ -0,0 +1,69 @@
-- Scripts juste pour tester l'effet train
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
-- roue des couleurs: https://iro.js.org/?ref=oldsite
print("\n a_chapeau_z.lua zf181204.2057 \n")
znbled=36
function RGB_clear()
ws2812.init()
buffer = ws2812.newBuffer(znbled, 3)
buffer:fill(0, 0, 0)
ws2812.write(buffer)
end
RGB_clear()
fadeLevel=3
train1_R=255
train1_G=0
train1_B=0
train2_R=255
train2_G=0
train2_B=0
-- Buffer Train 1
myLedStrip1 = ws2812.newBuffer(znbled, 3)
myLedStrip1:fill(0,0,0)
myLedStrip1:set(1, train1_G, train1_R, train1_B)
myLedStrip1:fade(fadeLevel)
myLedStrip1:set(2, train1_G, train1_R, train1_B)
myLedStrip1:fade(fadeLevel)
myLedStrip1:set(3, train1_G, train1_R, train1_B)
myLedStrip1:fade(fadeLevel)
myLedStrip1:set(4, train1_G, train1_R, train1_B)
ws2812.write(myLedStrip1)
-- Buffer Train 2
myLedStrip2 = ws2812.newBuffer(znbled, 3)
myLedStrip2:fill(0,0,0)
myLedStrip2:set(znbled, train2_G, train2_R, train2_B)
myLedStrip2:fade(fadeLevel)
myLedStrip2:set(znbled-1, train2_G, train2_R, train2_B)
myLedStrip2:fade(fadeLevel)
myLedStrip2:set(znbled-2, train2_G, train2_R, train2_B)
myLedStrip2:fade(fadeLevel)
myLedStrip2:set(znbled-3, train2_G, train2_R, train2_B)
ws2812.write(myLedStrip2)
-- Buffer Train Total
myLedStrip = ws2812.newBuffer(znbled, 3)
myLedStrip:mix(255, myLedStrip1, 255, myLedStrip2)
ws2812.write(myLedStrip)
-- Train move
zspeed=25
train2timer1=tmr.create()
tmr.alarm(train2timer1, zspeed, tmr.ALARM_AUTO, function()
myLedStrip1:shift(1, ws2812.SHIFT_CIRCULAR) -- direction →
myLedStrip2:shift(-1, ws2812.SHIFT_CIRCULAR) -- direction ←
myLedStrip:mix(255, myLedStrip1, 255, myLedStrip2) -- mix both train
ws2812.write(myLedStrip)
end)