89 lines
1.6 KiB
Lua
Executable file
89 lines
1.6 KiB
Lua
Executable file
-- programme principal qui charge les fonctions des autres programmes
|
|
|
|
-- fonction de roue RGB
|
|
function wheelRGB(pos) -- pos 0 -> 255 couleur
|
|
pos = 255 - pos
|
|
if (pos < 85) then
|
|
return 255 - pos * 3, 0, pos * 3
|
|
elseif (pos < 170) then
|
|
pos = pos - 85
|
|
return 0, pos * 3, 255 - pos * 3
|
|
else
|
|
pos = pos - 170
|
|
return pos * 3, 255 - pos * 3, 0
|
|
end
|
|
end
|
|
|
|
-- fonction permettant d'afficher la température du CPU
|
|
function printTemp()
|
|
print("Température du CPU :", cpu.temperature())
|
|
end
|
|
|
|
-- fonction permettant de trouver l'addresse I2C d'un écran OLED
|
|
function findaddr()
|
|
i2c.setpins(1, 18, 19)
|
|
ic = i2c.attach(i2c.I2C1, i2c.MASTER)
|
|
|
|
for i = 0, 127 do
|
|
try(
|
|
function ()
|
|
ic:start()
|
|
ic:address(i, false)
|
|
ic:stop()
|
|
print(string.format("found # %x", i))
|
|
end,
|
|
|
|
function()
|
|
print("failed")
|
|
end,
|
|
|
|
function() end
|
|
)
|
|
end
|
|
end
|
|
|
|
function min(tab)
|
|
local min = tab[1]
|
|
for i=1,#tab do
|
|
if tab[i] < min then min = tab[i] end
|
|
end
|
|
return min
|
|
end
|
|
|
|
function max(tab)
|
|
local max = tab[1]
|
|
for i=1,#tab do
|
|
if tab[i] > max then max = tab[i] end
|
|
end
|
|
return max
|
|
end
|
|
|
|
function avg(tab)
|
|
local sum = 0
|
|
for i=1,#tab do
|
|
sum = sum + tab[i]
|
|
end
|
|
return sum / #tab
|
|
end
|
|
|
|
function split(text, splitter)
|
|
local start, _end = text:find(splitter)
|
|
if not start then
|
|
return text, ""
|
|
end
|
|
return text:sub(1, start - 1), text:sub(_end + 1)
|
|
end
|
|
|
|
|
|
-- charge tout nos fichiers lua
|
|
dofile("leds.lua")
|
|
dofile("buzz.lua")
|
|
dofile("neopixel.lua")
|
|
dofile("encoder.lua")
|
|
dofile("dht22.lua")
|
|
dofile("screen.lua")
|
|
dofile("wifi.lua")
|
|
|
|
-- attache l'écran
|
|
attachscreen(18, 19, 0x3C)
|
|
console("Hello, world!")
|