Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
karudu
/
IoTvalgustus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
56ded8d6
authored
Apr 27, 2023
by
Karl Udu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enkooder saadab MQTT sõnumeid
parent
a3a6dc7a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
15 deletions
ProjektEnkooder/platformio.ini
ProjektEnkooder/src/main.cpp
ProjektEnkooder/platformio.ini
View file @
56ded8d6
...
...
@@ -12,6 +12,7 @@
platform
=
espressif8266
board
=
d1_mini
framework
=
arduino
;upload_port = COM4 ; vasak
upload_port
=
COM5 ; parem
lib_deps
=
ITTIoT, ClickEncoder
...
...
ProjektEnkooder/src/main.cpp
View file @
56ded8d6
...
...
@@ -13,9 +13,10 @@
ClickEncoder
encoder
=
ClickEncoder
(
ENC_PINA
,
ENC_PINB
,
ENC_BTN
,
ENC_STEPS_PER_NOTCH
);
#define LEVEL_MIN 0
#define LEVEL_MAX 99
#define LEVEL_DEFAULT 50
uint32_t
level
=
LEVEL_DEFAULT
;
#define LEVEL_MAX 255
#define LEVEL_DEFAULT 127
#define LEVEL_STEP 4
int32_t
level
=
LEVEL_DEFAULT
;
void
iot_connected
()
{
...
...
@@ -28,43 +29,44 @@ void setup()
Serial
.
begin
(
115200
);
// setting up serial connection parameter
Serial
.
println
(
"Booting"
);
/*
iot.setConfig("wname", WIFI_NAME);
iot
.
setConfig
(
"wname"
,
WIFI_NAME
);
iot
.
setConfig
(
"wpass"
,
WIFI_PASSWORD
);
iot
.
setConfig
(
"msrv"
,
"193.40.245.72"
);
iot
.
setConfig
(
"mport"
,
"1883"
);
iot
.
setConfig
(
"muser"
,
"test"
);
iot
.
setConfig
(
"mpass"
,
"test"
);
iot
.
printConfig
();
// print IoT json config to serial
iot.setup(); // Initialize IoT library
*/
iot
.
setup
();
// Initialize IoT library
}
void
loop
()
{
//
iot.handle(); // IoT behind the plan work, it should be periodically called
iot
.
handle
();
// IoT behind the plan work, it should be periodically called
delay
(
5
);
encoder
.
service
();
static
int16_t
oldPosition
,
newPosition
;
newPosition
+=
encoder
.
getValue
();
// Read encoder value
char
StrBuf
[
16
];
if
(
newPosition
>
oldPosition
)
{
if
(
level
!=
LEVEL_MAX
)
{
level
++
;
//iot.publishMsg("enc", level)
;
Serial
.
print
(
"level "
);
Serial
.
println
(
level
);
level
+=
LEVEL_STEP
;
if
(
level
>
LEVEL_MAX
)
level
=
LEVEL_MAX
;
sprintf
(
StrBuf
,
"%d"
,
level
);
iot
.
publishMsg
(
"light_level"
,
StrBuf
);
}
}
else
if
(
newPosition
<
oldPosition
)
{
if
(
level
!=
LEVEL_MIN
)
{
level
--
;
//iot.publishMsg("enc", level)
;
Serial
.
print
(
"level "
);
Serial
.
println
(
level
);
level
-=
LEVEL_STEP
;
if
(
level
<
LEVEL_MIN
)
level
=
LEVEL_MIN
;
sprintf
(
StrBuf
,
"%d"
,
level
);
iot
.
publishMsg
(
"light_level"
,
StrBuf
);
}
}
oldPosition
=
newPosition
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment