Add code for archiv drawers
This commit is contained in:
parent
4459df1f18
commit
a2945bad9a
5
drawers/.gitignore
vendored
Normal file
5
drawers/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
14
drawers/platformio.ini
Normal file
14
drawers/platformio.ini
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:megaatmega2560]
|
||||||
|
platform = atmelavr
|
||||||
|
board = megaatmega2560
|
||||||
|
framework = arduino
|
||||||
143
drawers/src/main.cpp
Normal file
143
drawers/src/main.cpp
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
ARCHIV – Arduino Mega (I2C-Slave)
|
||||||
|
Alle ehemaligen Puls-Signale jetzt rein logisch über I2C
|
||||||
|
========================================================= */
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
// I2C
|
||||||
|
const uint8_t I2C_ADDR = 0x10;
|
||||||
|
|
||||||
|
// I2C-Befehle (müssen zum Master-Code passen)
|
||||||
|
const uint8_t CMD_LED_LOCK_TOGGLE = 0x01;
|
||||||
|
const uint8_t CMD_ALLES_GESCHAFFT = 0x02;
|
||||||
|
const uint8_t CMD_AUSWAHLRAD_LINKS = 0x03;
|
||||||
|
const uint8_t CMD_AUSWAHLRAD_RECHTS = 0x04;
|
||||||
|
|
||||||
|
/* -------------------------
|
||||||
|
Hardware
|
||||||
|
------------------------- */
|
||||||
|
|
||||||
|
struct Schublade {
|
||||||
|
int schlossPin;
|
||||||
|
int ledPin;
|
||||||
|
};
|
||||||
|
|
||||||
|
Schublade schubladen[8] = {
|
||||||
|
{6, 30},
|
||||||
|
{9, 32},
|
||||||
|
{7, 31},
|
||||||
|
{8, 33},
|
||||||
|
{2, 29},
|
||||||
|
{12, 28},
|
||||||
|
{11, 27},
|
||||||
|
{10, 26}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* -------------------------
|
||||||
|
Zustände
|
||||||
|
------------------------- */
|
||||||
|
|
||||||
|
int currentIndex = 0;
|
||||||
|
bool ledsLocked = false;
|
||||||
|
bool schlossOffen = false;
|
||||||
|
|
||||||
|
/* -------------------------
|
||||||
|
Schloss-Timer
|
||||||
|
------------------------- */
|
||||||
|
|
||||||
|
const unsigned long SCHLOSS_DAUER = 750;
|
||||||
|
unsigned long schlossStart = 0;
|
||||||
|
|
||||||
|
/* ========================================================= */
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Wire.begin(I2C_ADDR);
|
||||||
|
Wire.onReceive(onI2CReceive);
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
pinMode(schubladen[i].ledPin, OUTPUT);
|
||||||
|
pinMode(schubladen[i].schlossPin, OUTPUT);
|
||||||
|
digitalWrite(schubladen[i].ledPin, LOW);
|
||||||
|
digitalWrite(schubladen[i].schlossPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateLEDs();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================================================= */
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
handleSchlossTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================================================
|
||||||
|
I2C-Callback
|
||||||
|
========================================================= */
|
||||||
|
|
||||||
|
void onI2CReceive(int len) {
|
||||||
|
while (Wire.available()) {
|
||||||
|
uint8_t cmd = Wire.read();
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
|
||||||
|
case CMD_LED_LOCK_TOGGLE:
|
||||||
|
ledsLocked = !ledsLocked;
|
||||||
|
updateLEDs();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_ALLES_GESCHAFFT:
|
||||||
|
openSchlossTimed();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_AUSWAHLRAD_RECHTS:
|
||||||
|
if (!ledsLocked) {
|
||||||
|
currentIndex = (currentIndex + 1) % 8;
|
||||||
|
updateLEDs();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_AUSWAHLRAD_LINKS:
|
||||||
|
if (!ledsLocked) {
|
||||||
|
currentIndex = (currentIndex + 7) % 8;
|
||||||
|
updateLEDs();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================================================
|
||||||
|
LED-Steuerung
|
||||||
|
========================================================= */
|
||||||
|
|
||||||
|
void updateLEDs() {
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
digitalWrite(schubladen[i].ledPin, LOW);
|
||||||
|
|
||||||
|
if (!ledsLocked)
|
||||||
|
digitalWrite(schubladen[currentIndex].ledPin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================================================
|
||||||
|
SCHLOSS – zeitgesteuert
|
||||||
|
========================================================= */
|
||||||
|
|
||||||
|
void openSchlossTimed() {
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
digitalWrite(schubladen[i].schlossPin, LOW);
|
||||||
|
|
||||||
|
digitalWrite(schubladen[currentIndex].schlossPin, HIGH);
|
||||||
|
schlossOffen = true;
|
||||||
|
schlossStart = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleSchlossTimeout() {
|
||||||
|
if (schlossOffen && millis() - schlossStart >= SCHLOSS_DAUER) {
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
digitalWrite(schubladen[i].schlossPin, LOW);
|
||||||
|
|
||||||
|
schlossOffen = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user