- ajouté le petit test d'Alex pour les LED RGB

- commencé à tester les LED RGB de manière simple
- descendu un nouveau firmware pour les LED RGB
This commit is contained in:
Christian Zufferey
2018-11-06 08:15:52 +01:00
parent 8abc823276
commit 1d839f8aaa
20 changed files with 350 additions and 6 deletions

BIN
LED_WS2812/Alex/PoC.tar Normal file

Binary file not shown.

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,15 @@
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')

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,23 @@
--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)

View File

@@ -0,0 +1,17 @@
-- 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 zf181105.1428 \n")
print("Initializing LED strip...")
ws2812.init()
ws2812_effects.stop()
strip_buffer = ws2812.newBuffer(3, 3)
ws2812.write(string.char(0, 255, 0, 255, 0, 0, 0, 0, 255))
ws2812.write(string.char(255, 0, 255, 0, 255, 255, 255, 255, 0))
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,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,8 @@
-- Scripts à charger au moment du boot
print("\n start_boot.lua zf181105.1122 \n")
print("starting webleds...")
print()
dofile('webleds.lua')

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(3, 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,18 @@
-- 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()

Binary file not shown.

View File

@@ -1,9 +1,10 @@
-- programme pour faire clignoter une LED avec un rapport on/off
--zf20180717.1118
print("\n blink_led1.lua zf181105.1114 \n")
zLED=0
zTm_On_LED = 500 --> en ms
zTm_Off_LED = 500 --> en ms
zTm_On_LED = 200 --> en ms
zTm_Off_LED = 200 --> en ms
zFlag_LED = 0
function blink_LED ()

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 zf181105.1111 \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,9 +1,10 @@
-- programme pour faire clignoter une LED avec un rapport on/off
--zf20180717.1118
print("\n blink_led1.lua zf181105.1114 \n")
zLED=0
zTm_On_LED = 900 --> en ms
zTm_Off_LED = 900 --> en ms
zTm_On_LED = 200 --> en ms
zTm_Off_LED = 200 --> en ms
zFlag_LED = 0
function blink_LED ()

32
flash_led_xfois.lua Normal file
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 zf181105.1111 \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 ()

23
initz.lua Normal file
View File

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

7
start_boot.lua Normal file
View File

@@ -0,0 +1,7 @@
-- Scripts à charger au moment du boot
print("\n start_boot.lua zf181017.1021 \n")
dofile("blink_led1.lua")