commit
This commit is contained in:
parent
e92123ab22
commit
9a82196fd1
3 changed files with 104 additions and 84 deletions
24
dht22.lua
24
dht22.lua
|
@ -23,30 +23,6 @@ function humi_neo(min, max)
|
|||
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 temp_humi_avg()
|
||||
temps = {}
|
||||
humis = {}
|
||||
|
|
47
main.lua
47
main.lua
|
@ -19,6 +19,53 @@ 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
|
||||
|
||||
-- charge tout nos fichiers lua
|
||||
dofile("leds.lua")
|
||||
dofile("buzz.lua")
|
||||
|
|
113
screen.lua
113
screen.lua
|
@ -6,40 +6,28 @@
|
|||
-- cls()
|
||||
-- console()
|
||||
|
||||
-- changer les valeurs qui suivent en fonction de
|
||||
-- vos branchements
|
||||
|
||||
-- GPIO pour I2C
|
||||
local sda = 18
|
||||
local scl = 19
|
||||
|
||||
-- adresse ecran I2C
|
||||
i2cadd = 0x3C
|
||||
|
||||
-- configuration
|
||||
local reset16 = false -- reset ecran
|
||||
i2c.setpins(0,sda,scl) -- config i2C
|
||||
|
||||
-- ecran
|
||||
if reset16 then -- reset pour l'ecran si necessaire
|
||||
pio.pin.setdir(pio.OUTPUT, pio.GPIO16);
|
||||
pio.pin.setlow(pio.GPIO16)
|
||||
tmr.delayms(50);
|
||||
pio.pin.sethigh(pio.GPIO16)
|
||||
tmr.delayms(50);
|
||||
end
|
||||
|
||||
pcall( function() -- pas d'erreur
|
||||
-- fonction permettant se s'attacher à l'écran
|
||||
function attachscreen(sda, scl, i2cadd)
|
||||
try (
|
||||
function ()
|
||||
i2c.setpins(0,sda,scl)
|
||||
gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.LANDSCAPE, false, i2cadd)
|
||||
gdisplay.clear()
|
||||
gdisplay.setfont(gdisplay.FONT_LCD)
|
||||
gdisplay.setwrap(false)
|
||||
end)
|
||||
end,
|
||||
|
||||
function (where, line, error, message)
|
||||
print("Couldn't attach the screen.\nError in "..where.." at "..line.." "..error..": "..message)
|
||||
end,
|
||||
|
||||
function () end
|
||||
)
|
||||
end
|
||||
|
||||
local consolepos = 0
|
||||
local consoletab = {}
|
||||
local consolemax = 6
|
||||
|
||||
local oledflip = 1
|
||||
|
||||
function flip()
|
||||
|
@ -101,37 +89,46 @@ function top()
|
|||
end
|
||||
end
|
||||
|
||||
function fonts()
|
||||
cls()
|
||||
gdisplay.setfont(gdisplay.FONT_DEFAULT)
|
||||
console("DEFAULT")
|
||||
tmr.delay(5); cls()
|
||||
gdisplay.setfont(gdisplay.FONT_DEJAVU18)
|
||||
console("DEJAVU18")
|
||||
tmr.delay(5); cls()
|
||||
gdisplay.setfont(gdisplay.FONT_DEJAVU24)
|
||||
console("DEJAVU24")
|
||||
tmr.delay(5); cls()
|
||||
gdisplay.setfont(gdisplay.FONT_UBUNTU16)
|
||||
console("UBUNTU16")
|
||||
tmr.delay(5); cls()
|
||||
gdisplay.setfont(gdisplay.FONT_COMIC24)
|
||||
console("COMIC24")
|
||||
tmr.delay(5); cls()
|
||||
gdisplay.setfont(gdisplay.FONT_TOONEY32)
|
||||
console("TOONEY32")
|
||||
tmr.delay(5); cls()
|
||||
gdisplay.setfont(gdisplay.FONT_MINYA24)
|
||||
console("MINYA24")
|
||||
tmr.delay(5); cls()
|
||||
gdisplay.setfont(gdisplay.FONT_7SEG)
|
||||
console("7SEG")
|
||||
tmr.delay(5); cls()
|
||||
gdisplay.setfont(gdisplay.FONT_LCD)
|
||||
console("LCD")
|
||||
end
|
||||
-- fonction permettant de dessiner une courbe selon l'humidité captée par le capteur DHT22
|
||||
function displayhumi()
|
||||
attachscreen(18, 19, 0x3C)
|
||||
s = sensor.attach("DHT22", pio.GPIO21)
|
||||
tmr.delayms(500)
|
||||
width, height = gdisplay.getscreensize()
|
||||
|
||||
pcall( function()
|
||||
values = {}
|
||||
min_val = s:read("humidity")
|
||||
max_val = s:read("humidity")
|
||||
|
||||
while true do
|
||||
humi = s:read("humidity")
|
||||
-- changement des valeurs min et max
|
||||
if humi < min_val then min_val = humi
|
||||
elseif humi > max_val then max_val = humi end
|
||||
-- si le tableau est plein alors on affiche la courbe
|
||||
if #values == 10 then
|
||||
for i=1,9 do
|
||||
values[i] = values[i + 1]
|
||||
end
|
||||
values[10] = humi
|
||||
cls()
|
||||
console(">")
|
||||
end)
|
||||
-- on dessine chaque partie de la courbe
|
||||
for i=1,9 do
|
||||
-- on dessine la partie de courbe
|
||||
gdisplay.line(
|
||||
{
|
||||
math.floor(i/10 * width), -- coordonnée x du premier point
|
||||
math.floor((values[i] - min_val)/(max_val - min_val) * (height - 10) + 5) -- valeur comprise entre la val min et la val max avec des espaces de 5px et haut et en bas
|
||||
},
|
||||
{
|
||||
math.floor((i + 1)/10 * width), -- coordonnée x du deuxième point
|
||||
math.floor((values[i + 1] - min_val)/(max_val - min_val) * (height - 10) + 5) -- valeur comprise entre la val min et la val max avec des espaces de 5px et haut et en bas
|
||||
}
|
||||
)
|
||||
end
|
||||
else
|
||||
values[#values + 1] = humi
|
||||
end
|
||||
tmr.delayms(500)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue