Implement and document Arduino software
This commit is contained in:
parent
28de70e732
commit
001c7cd568
17 changed files with 648 additions and 70 deletions
70
source/arduino/arduino.ino
Normal file
70
source/arduino/arduino.ino
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
Copyright (c):
|
||||
|
||||
Philipp Matthias Schäfer (philipp.matthias.schaefer@posteo.de), 2020
|
||||
|
||||
This file is part of the KrautStatus' Arduino code.
|
||||
|
||||
The Clean CommonMark library is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Clean CommonMark library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License along
|
||||
with the Clean CommonMark library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <uTimerLib.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "matrix.h"
|
||||
#include "sensor.h"
|
||||
#include "serial.h"
|
||||
#include "wifi.h"
|
||||
|
||||
const unsigned long int MATRIX_UPDATE_FREQUENCY = 1;
|
||||
|
||||
void setup() {
|
||||
serial_setup();
|
||||
matrix_setup();
|
||||
|
||||
boolean wifi_result = matrix_show_scan_and_run(wifi_setup);
|
||||
if (!wifi_result) {
|
||||
matrix_show_failure();
|
||||
while(true);
|
||||
}
|
||||
|
||||
sensor_setup();
|
||||
|
||||
start_matrix_update();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int packetSize = Udp.parsePacket();
|
||||
if (packetSize) {
|
||||
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
|
||||
Udp.write(uint8_t(sensor_get_door_state()));
|
||||
Udp.endPacket();
|
||||
}
|
||||
}
|
||||
|
||||
void start_matrix_update() {
|
||||
TimerLib.setInterval_us(matrix_update, 1000000 / MATRIX_UPDATE_FREQUENCY);
|
||||
}
|
||||
|
||||
void matrix_update() {
|
||||
switch (sensor_get_door_state()) {
|
||||
OPEN:
|
||||
matrix_fill(GREEN);
|
||||
break;
|
||||
CLOSED:
|
||||
matrix_fill(BLACK);
|
||||
break;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue