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
|
||||||
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()
|
function temp_humi_avg()
|
||||||
temps = {}
|
temps = {}
|
||||||
humis = {}
|
humis = {}
|
||||||
|
|
47
main.lua
47
main.lua
|
@ -19,6 +19,53 @@ function printTemp()
|
||||||
print("Température du CPU :", cpu.temperature())
|
print("Température du CPU :", cpu.temperature())
|
||||||
end
|
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
|
-- charge tout nos fichiers lua
|
||||||
dofile("leds.lua")
|
dofile("leds.lua")
|
||||||
dofile("buzz.lua")
|
dofile("buzz.lua")
|
||||||
|
|
117
screen.lua
117
screen.lua
|
@ -6,40 +6,28 @@
|
||||||
-- cls()
|
-- cls()
|
||||||
-- console()
|
-- console()
|
||||||
|
|
||||||
-- changer les valeurs qui suivent en fonction de
|
-- fonction permettant se s'attacher à l'écran
|
||||||
-- vos branchements
|
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,
|
||||||
|
|
||||||
-- GPIO pour I2C
|
function (where, line, error, message)
|
||||||
local sda = 18
|
print("Couldn't attach the screen.\nError in "..where.." at "..line.." "..error..": "..message)
|
||||||
local scl = 19
|
end,
|
||||||
|
|
||||||
-- adresse ecran I2C
|
function () end
|
||||||
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
|
end
|
||||||
|
|
||||||
pcall( function() -- pas d'erreur
|
|
||||||
gdisplay.attach(gdisplay.SSD1306_128_64, gdisplay.LANDSCAPE, false, i2cadd)
|
|
||||||
gdisplay.clear()
|
|
||||||
gdisplay.setfont(gdisplay.FONT_LCD)
|
|
||||||
gdisplay.setwrap(false)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local consolepos = 0
|
local consolepos = 0
|
||||||
local consoletab = {}
|
local consoletab = {}
|
||||||
local consolemax = 6
|
local consolemax = 6
|
||||||
|
|
||||||
local oledflip = 1
|
local oledflip = 1
|
||||||
|
|
||||||
function flip()
|
function flip()
|
||||||
|
@ -101,37 +89,46 @@ function top()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function fonts()
|
-- fonction permettant de dessiner une courbe selon l'humidité captée par le capteur DHT22
|
||||||
cls()
|
function displayhumi()
|
||||||
gdisplay.setfont(gdisplay.FONT_DEFAULT)
|
attachscreen(18, 19, 0x3C)
|
||||||
console("DEFAULT")
|
s = sensor.attach("DHT22", pio.GPIO21)
|
||||||
tmr.delay(5); cls()
|
tmr.delayms(500)
|
||||||
gdisplay.setfont(gdisplay.FONT_DEJAVU18)
|
width, height = gdisplay.getscreensize()
|
||||||
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
|
|
||||||
|
|
||||||
pcall( function()
|
values = {}
|
||||||
cls()
|
min_val = s:read("humidity")
|
||||||
console(">")
|
max_val = s:read("humidity")
|
||||||
end)
|
|
||||||
|
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()
|
||||||
|
-- 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