Tweak dashboard update interval to help with battery life, add status LED just in case something pops up during operation for better indication of state, add DIP switch code and tweak the DIP switch i2c code to support two 8 pin DIP switches and report data via i2c (not integrated into dashboard yet)
This commit is contained in:
parent
88a48da595
commit
3d0dbe28fe
|
@ -15,16 +15,18 @@
|
|||
void setup() {
|
||||
Wire.begin(); // join i2c bus (address optional for master)
|
||||
Serial.begin(115200); // start serial for output
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Wire.requestFrom(0x5F, sizeof(int)); // request 6 bytes from slave device #8
|
||||
|
||||
//while (Wire.available()) { // slave may send less than requested
|
||||
uint8_t value = Wire.read(); // receive a byte as character
|
||||
Serial.println(value); // print the character
|
||||
//}
|
||||
|
||||
Wire.requestFrom(0x65, 2);
|
||||
// Wait for data to become available -- can be a delayed response due to # of pins to enumerate
|
||||
while(!Wire.available());
|
||||
byte dip_1 = Wire.read();
|
||||
byte dip_2 = Wire.read();
|
||||
Serial.print("DIP 1: ");
|
||||
Serial.println(dip_1, BIN);
|
||||
Serial.print("DIP 2: ");
|
||||
Serial.println(dip_2, BIN);
|
||||
delay(500);
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
|
@ -28,10 +28,15 @@
|
|||
// sda: 17
|
||||
// scl: 19
|
||||
|
||||
// DIP Switch ATTiny Pins
|
||||
// DIP Switch 1 ATTiny Pins
|
||||
// 2 - 9
|
||||
|
||||
#define I2C_ADDRESS 0x96
|
||||
// DIP Switch 2 ATTiny Pins
|
||||
// 1
|
||||
// 11-16
|
||||
// 18
|
||||
|
||||
#define I2C_ADDRESS 0x65
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
|
@ -44,6 +49,14 @@ void setup() {
|
|||
pinMode(5, INPUT);
|
||||
pinMode(6, INPUT);
|
||||
pinMode(7, INPUT);
|
||||
pinMode(17, INPUT);
|
||||
pinMode(8, INPUT);
|
||||
pinMode(9, INPUT);
|
||||
pinMode(10, INPUT);
|
||||
pinMode(11, INPUT);
|
||||
pinMode(12, INPUT);
|
||||
pinMode(13, INPUT);
|
||||
pinMode(15, INPUT);
|
||||
|
||||
Wire.begin(I2C_ADDRESS);
|
||||
Wire.onRequest(requestEvent);
|
||||
|
@ -55,15 +68,24 @@ void loop() {
|
|||
|
||||
// function that executes whenever data is requested by master
|
||||
// this function is registered as an event, see setup()
|
||||
byte dip_switch = 0b00000000;
|
||||
byte dip_switches[] = {0b00000000, 0b00000000};
|
||||
void requestEvent() {
|
||||
bitWrite(dip_switch, 0, digitalRead(0));
|
||||
bitWrite(dip_switch, 1, digitalRead(1));
|
||||
bitWrite(dip_switch, 2, digitalRead(2));
|
||||
bitWrite(dip_switch, 3, digitalRead(3));
|
||||
bitWrite(dip_switch, 4, digitalRead(4));
|
||||
bitWrite(dip_switch, 5, digitalRead(5));
|
||||
bitWrite(dip_switch, 6, digitalRead(6));
|
||||
bitWrite(dip_switch, 7, digitalRead(7));
|
||||
Wire.write(dip_switch);
|
||||
bitWrite(dip_switches[0], 7, digitalRead(0));
|
||||
bitWrite(dip_switches[0], 6, digitalRead(1));
|
||||
bitWrite(dip_switches[0], 5, digitalRead(2));
|
||||
bitWrite(dip_switches[0], 4, digitalRead(3));
|
||||
bitWrite(dip_switches[0], 3, digitalRead(4));
|
||||
bitWrite(dip_switches[0], 2, digitalRead(5));
|
||||
bitWrite(dip_switches[0], 1, digitalRead(6));
|
||||
bitWrite(dip_switches[0], 0, digitalRead(7));
|
||||
|
||||
bitWrite(dip_switches[1], 0, digitalRead(15));
|
||||
bitWrite(dip_switches[1], 1, digitalRead(13));
|
||||
bitWrite(dip_switches[1], 2, digitalRead(12));
|
||||
bitWrite(dip_switches[1], 3, digitalRead(11));
|
||||
bitWrite(dip_switches[1], 4, digitalRead(10));
|
||||
bitWrite(dip_switches[1], 5, digitalRead(9));
|
||||
bitWrite(dip_switches[1], 6, digitalRead(8));
|
||||
bitWrite(dip_switches[1], 7, digitalRead(17));
|
||||
Wire.write(dip_switches, sizeof(dip_switches));
|
||||
}
|
||||
|
|
|
@ -115,11 +115,19 @@ esphome:
|
|||
- lambda: |-
|
||||
digitalWrite(13, LOW);
|
||||
|
||||
# Basic status infos via blinky LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
status_led:
|
||||
pin:
|
||||
number: 32
|
||||
inverted: True
|
||||
|
||||
# WiFi config
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
domain: !secret node_domain
|
||||
power_save_mode: light
|
||||
|
||||
# Enable I2C (Qwiic and others)
|
||||
i2c:
|
||||
|
@ -134,7 +142,7 @@ spi:
|
|||
deep_sleep:
|
||||
id: deep_sleep_main
|
||||
run_duration: 5min
|
||||
sleep_duration: 1h
|
||||
sleep_duration: 90min
|
||||
wakeup_pin_mode: INVERT_WAKEUP # stop caring and be judicious about tolerance of goofy pin modes
|
||||
|
||||
# Enable logging
|
||||
|
|
Loading…
Reference in New Issue