diff --git a/Documentation/Ai-Thinker-ESP-12F-ESP8266MOD_C82891.pdf b/Documentation/Ai-Thinker-ESP-12F-ESP8266MOD_C82891.pdf new file mode 100644 index 0000000..ac50d6b Binary files /dev/null and b/Documentation/Ai-Thinker-ESP-12F-ESP8266MOD_C82891.pdf differ diff --git a/LED_RGB_WS2812/chapeau_led/README.md b/LED_RGB_WS2812/chapeau_led/README.md new file mode 100644 index 0000000..fd9b63b --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/README.md @@ -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 + + + + + diff --git a/LED_RGB_WS2812/chapeau_led/a_train3.lua b/LED_RGB_WS2812/chapeau_led/a_train3.lua new file mode 100644 index 0000000..258aab1 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/a_train3.lua @@ -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) diff --git a/LED_RGB_WS2812/chapeau_led/az_init_led.lua b/LED_RGB_WS2812/chapeau_led/az_init_led.lua new file mode 100644 index 0000000..79a5380 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/az_init_led.lua @@ -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.") + diff --git a/LED_RGB_WS2812/chapeau_led/boot.lua b/LED_RGB_WS2812/chapeau_led/boot.lua new file mode 100644 index 0000000..c98546e --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/boot.lua @@ -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) + + diff --git a/LED_RGB_WS2812/chapeau_led/flash_led_xfois.lua b/LED_RGB_WS2812/chapeau_led/flash_led_xfois.lua new file mode 100644 index 0000000..afc4adb --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/flash_led_xfois.lua @@ -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 () + + + diff --git a/LED_RGB_WS2812/guirlandes noël/a_test_fill.lua b/LED_RGB_WS2812/chapeau_led/goodies/a_test_fill.lua similarity index 100% rename from LED_RGB_WS2812/guirlandes noël/a_test_fill.lua rename to LED_RGB_WS2812/chapeau_led/goodies/a_test_fill.lua diff --git a/LED_RGB_WS2812/guirlandes noël/a_test_train.lua b/LED_RGB_WS2812/chapeau_led/goodies/a_train1.lua similarity index 85% rename from LED_RGB_WS2812/guirlandes noël/a_test_train.lua rename to LED_RGB_WS2812/chapeau_led/goodies/a_train1.lua index 826cd62..43b4201 100644 --- a/LED_RGB_WS2812/guirlandes noël/a_test_train.lua +++ b/LED_RGB_WS2812/chapeau_led/goodies/a_train1.lua @@ -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 diff --git a/LED_RGB_WS2812/guirlandes noël/blink_led2.lua b/LED_RGB_WS2812/chapeau_led/goodies/blink_led2.lua similarity index 100% rename from LED_RGB_WS2812/guirlandes noël/blink_led2.lua rename to LED_RGB_WS2812/chapeau_led/goodies/blink_led2.lua diff --git a/LED_RGB_WS2812/guirlandes noël/cat.lua b/LED_RGB_WS2812/chapeau_led/goodies/cat.lua similarity index 100% rename from LED_RGB_WS2812/guirlandes noël/cat.lua rename to LED_RGB_WS2812/chapeau_led/goodies/cat.lua diff --git a/LED_RGB_WS2812/guirlandes noël/dir.lua b/LED_RGB_WS2812/chapeau_led/goodies/dir.lua similarity index 100% rename from LED_RGB_WS2812/guirlandes noël/dir.lua rename to LED_RGB_WS2812/chapeau_led/goodies/dir.lua diff --git a/LED_RGB_WS2812/chapeau_led/goodies/index.html b/LED_RGB_WS2812/chapeau_led/goodies/index.html new file mode 100644 index 0000000..62283da --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/goodies/index.html @@ -0,0 +1,60 @@ + + + +LED Strip Control + + + + +

LED strip control page

+ +

Choose an effect:

+ + +

Pick a color:

+ + + + + diff --git a/LED_RGB_WS2812/guirlandes noël/initz - copie.lua b/LED_RGB_WS2812/chapeau_led/goodies/initz - copie.lua similarity index 100% rename from LED_RGB_WS2812/guirlandes noël/initz - copie.lua rename to LED_RGB_WS2812/chapeau_led/goodies/initz - copie.lua diff --git a/LED_RGB_WS2812/chapeau_led/goodies/rm_files.lua b/LED_RGB_WS2812/chapeau_led/goodies/rm_files.lua new file mode 100644 index 0000000..81241cb --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/goodies/rm_files.lua @@ -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") diff --git a/LED_RGB_WS2812/chapeau_led/goodies/webleds.lua b/LED_RGB_WS2812/chapeau_led/goodies/webleds.lua new file mode 100644 index 0000000..81bd992 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/goodies/webleds.lua @@ -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) + diff --git a/LED_RGB_WS2812/chapeau_led/goodies/wifi_ap_start.lua b/LED_RGB_WS2812/chapeau_led/goodies/wifi_ap_start.lua new file mode 100644 index 0000000..60b5793 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/goodies/wifi_ap_start.lua @@ -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 diff --git a/LED_RGB_WS2812/chapeau_led/goodies/wifi_get_ip.lua b/LED_RGB_WS2812/chapeau_led/goodies/wifi_get_ip.lua new file mode 100644 index 0000000..82bcdc2 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/goodies/wifi_get_ip.lua @@ -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) diff --git a/LED_RGB_WS2812/chapeau_led/goodies/wifi_info.lua b/LED_RGB_WS2812/chapeau_led/goodies/wifi_info.lua new file mode 100644 index 0000000..5062fcf --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/goodies/wifi_info.lua @@ -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 diff --git a/LED_RGB_WS2812/chapeau_led/goodies/wifi_off.lua b/LED_RGB_WS2812/chapeau_led/goodies/wifi_off.lua new file mode 100644 index 0000000..c1c7235 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/goodies/wifi_off.lua @@ -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()) +]] diff --git a/LED_RGB_WS2812/chapeau_led/initz.lua b/LED_RGB_WS2812/chapeau_led/initz.lua new file mode 100644 index 0000000..10066de --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/initz.lua @@ -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 + diff --git a/LED_RGB_WS2812/chapeau_led/repair.lua b/LED_RGB_WS2812/chapeau_led/repair.lua new file mode 100644 index 0000000..626b5e5 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/repair.lua @@ -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) +]] \ No newline at end of file diff --git a/LED_RGB_WS2812/fill_effect/README.md b/LED_RGB_WS2812/fill_effect/README.md new file mode 100644 index 0000000..c0db26e --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/README.md @@ -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 + + + diff --git a/LED_RGB_WS2812/fill_effect/a_guirlande.lua b/LED_RGB_WS2812/fill_effect/a_guirlande.lua new file mode 100644 index 0000000..34c95e3 --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/a_guirlande.lua @@ -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]) + + + + diff --git a/LED_RGB_WS2812/fill_effect/az_init_led.lua b/LED_RGB_WS2812/fill_effect/az_init_led.lua new file mode 100644 index 0000000..79a5380 --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/az_init_led.lua @@ -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.") + diff --git a/LED_RGB_WS2812/fill_effect/boot.lua b/LED_RGB_WS2812/fill_effect/boot.lua new file mode 100644 index 0000000..a6fe229 --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/boot.lua @@ -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) +]] + diff --git a/LED_RGB_WS2812/fill_effect/initz.lua b/LED_RGB_WS2812/fill_effect/initz.lua new file mode 100644 index 0000000..10066de --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/initz.lua @@ -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 + diff --git a/LED_RGB_WS2812/fill_effect/oldies/a_test_fill.lua b/LED_RGB_WS2812/fill_effect/oldies/a_test_fill.lua new file mode 100644 index 0000000..b015d37 --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/oldies/a_test_fill.lua @@ -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) + + + + diff --git a/LED_RGB_WS2812/fill_effect/oldies/blink_led2.lua b/LED_RGB_WS2812/fill_effect/oldies/blink_led2.lua new file mode 100644 index 0000000..70fa251 --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/oldies/blink_led2.lua @@ -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) diff --git a/LED_RGB_WS2812/fill_effect/oldies/cat.lua b/LED_RGB_WS2812/fill_effect/oldies/cat.lua new file mode 100644 index 0000000..7c309b9 --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/oldies/cat.lua @@ -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 diff --git a/LED_RGB_WS2812/fill_effect/oldies/dir.lua b/LED_RGB_WS2812/fill_effect/oldies/dir.lua new file mode 100644 index 0000000..8bf9414 --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/oldies/dir.lua @@ -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() diff --git a/LED_RGB_WS2812/fill_effect/oldies/initz - copie.lua b/LED_RGB_WS2812/fill_effect/oldies/initz - copie.lua new file mode 100644 index 0000000..80d817d --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/oldies/initz - copie.lua @@ -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 diff --git a/LED_RGB_WS2812/fill_effect/repair.lua b/LED_RGB_WS2812/fill_effect/repair.lua new file mode 100644 index 0000000..626b5e5 --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/repair.lua @@ -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) +]] \ No newline at end of file diff --git a/LED_RGB_WS2812/fill_effect/rm_files.lua b/LED_RGB_WS2812/fill_effect/rm_files.lua new file mode 100644 index 0000000..81241cb --- /dev/null +++ b/LED_RGB_WS2812/fill_effect/rm_files.lua @@ -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") diff --git a/LED_RGB_WS2812/guirlandes noël/a_guirlande.lua b/LED_RGB_WS2812/guirlandes noël/a_guirlande.lua new file mode 100644 index 0000000..34c95e3 --- /dev/null +++ b/LED_RGB_WS2812/guirlandes noël/a_guirlande.lua @@ -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]) + + + + diff --git a/LED_RGB_WS2812/guirlandes noël/az_init_led.lua b/LED_RGB_WS2812/guirlandes noël/az_init_led.lua index e9df15c..79a5380 100644 --- a/LED_RGB_WS2812/guirlandes noël/az_init_led.lua +++ b/LED_RGB_WS2812/guirlandes noël/az_init_led.lua @@ -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 -]] diff --git a/LED_RGB_WS2812/guirlandes noël/oldies/a_test_fill.lua b/LED_RGB_WS2812/guirlandes noël/oldies/a_test_fill.lua new file mode 100644 index 0000000..b015d37 --- /dev/null +++ b/LED_RGB_WS2812/guirlandes noël/oldies/a_test_fill.lua @@ -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) + + + + diff --git a/LED_RGB_WS2812/guirlandes noël/oldies/blink_led2.lua b/LED_RGB_WS2812/guirlandes noël/oldies/blink_led2.lua new file mode 100644 index 0000000..70fa251 --- /dev/null +++ b/LED_RGB_WS2812/guirlandes noël/oldies/blink_led2.lua @@ -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) diff --git a/LED_RGB_WS2812/guirlandes noël/oldies/cat.lua b/LED_RGB_WS2812/guirlandes noël/oldies/cat.lua new file mode 100644 index 0000000..7c309b9 --- /dev/null +++ b/LED_RGB_WS2812/guirlandes noël/oldies/cat.lua @@ -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 diff --git a/LED_RGB_WS2812/guirlandes noël/oldies/dir.lua b/LED_RGB_WS2812/guirlandes noël/oldies/dir.lua new file mode 100644 index 0000000..8bf9414 --- /dev/null +++ b/LED_RGB_WS2812/guirlandes noël/oldies/dir.lua @@ -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() diff --git a/LED_RGB_WS2812/guirlandes noël/oldies/initz - copie.lua b/LED_RGB_WS2812/guirlandes noël/oldies/initz - copie.lua new file mode 100644 index 0000000..80d817d --- /dev/null +++ b/LED_RGB_WS2812/guirlandes noël/oldies/initz - copie.lua @@ -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 diff --git a/LED_RGB_WS2812/train effect/effect3/a_test_train.lua b/LED_RGB_WS2812/train effect/effect3/a_test_train.lua deleted file mode 100644 index 826cd62..0000000 --- a/LED_RGB_WS2812/train effect/effect3/a_test_train.lua +++ /dev/null @@ -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) - - diff --git a/LED_RGB_WS2812/train effect/effect3/a_train3.lua b/LED_RGB_WS2812/train effect/effect3/a_train3.lua new file mode 100644 index 0000000..258aab1 --- /dev/null +++ b/LED_RGB_WS2812/train effect/effect3/a_train3.lua @@ -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)