Compare commits
No commits in common. "5080a004af1d63e232879cc9fd350f545df736f9" and "4459df1f18e648c624ec19e46cd5eb09a8176cfe" have entirely different histories.
5080a004af
...
4459df1f18
5
drawers/.gitignore
vendored
5
drawers/.gitignore
vendored
@ -1,5 +0,0 @@
|
|||||||
.pio
|
|
||||||
.vscode/.browse.c_cpp.db*
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
.vscode/launch.json
|
|
||||||
.vscode/ipch
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
; 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
|
|
||||||
@ -1,90 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#include <Wire.h>
|
|
||||||
|
|
||||||
const uint8_t I2C_ADDR = 0x10;
|
|
||||||
|
|
||||||
const uint8_t CMD_POWER_OFF = 0x01;
|
|
||||||
const uint8_t CMD_LIGHT_INDEX = 0x02;
|
|
||||||
const uint8_t CMD_DRAWER_INDEX = 0x03;
|
|
||||||
|
|
||||||
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}
|
|
||||||
};
|
|
||||||
|
|
||||||
void turnAllLedsOf() {
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
digitalWrite(schubladen[i].ledPin, LOW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void turnOnSingleLed(uint8_t indexOn) {
|
|
||||||
if (indexOn < 0 || indexOn >= 8)
|
|
||||||
return;
|
|
||||||
turnAllLedsOf();
|
|
||||||
digitalWrite(schubladen[indexOn].ledPin, HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
const int LOCK_THRESHOLD = 750;
|
|
||||||
unsigned long lockTimer = 0;
|
|
||||||
bool unlocked = false;
|
|
||||||
|
|
||||||
void openLock(uint8_t indexOn) {
|
|
||||||
unlocked = true;
|
|
||||||
lockTimer = millis();
|
|
||||||
digitalWrite(schubladen[indexOn].schlossPin, HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onI2CReceive(int len) {
|
|
||||||
while (Wire.available()) {
|
|
||||||
uint8_t cmd = Wire.read();
|
|
||||||
|
|
||||||
switch (cmd) {
|
|
||||||
|
|
||||||
case CMD_POWER_OFF:
|
|
||||||
turnAllLedsOf();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CMD_LIGHT_INDEX:
|
|
||||||
uint8_t index = Wire.read();
|
|
||||||
turnOnSingleLed(index);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CMD_DRAWER_INDEX:
|
|
||||||
uint8_t index = Wire.read();
|
|
||||||
openLock(index);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
if (unlocked && millis() - lockTimer >= LOCK_THRESHOLD) {
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
digitalWrite(schubladen[i].schlossPin, LOW);
|
|
||||||
}
|
|
||||||
unlocked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user