This commit is contained in:
lexa
2020-11-19 20:53:01 +03:00
parent 279e09334f
commit f198dc1b95
2 changed files with 29 additions and 20 deletions

View File

@@ -24,7 +24,7 @@ void setup() {
analogReference(INTERNAL); analogReference(INTERNAL);
sensorValue = analogRead(BATTERY_SENSE_PIN); sensorValue = analogRead(BATTERY_SENSE_PIN);
v = sensorValue * 0.004659498; v = sensorValue * 0.004659498;
batteryPcnt = (v * 100) / 4.2; batteryPcnt = (v-3.0 * 100) / 1.2;
while (myAHT10.begin() != true) while (myAHT10.begin() != true)
{ {
Serial.println(F("AHT10 not connected or fail to load calibration coefficient")); //(F()) save string to flash & keeps dynamic memory free Serial.println(F("AHT10 not connected or fail to load calibration coefficient")); //(F()) save string to flash & keeps dynamic memory free
@@ -53,7 +53,7 @@ void loop() {
send(msgMillis.set(cRun)); send(msgMillis.set(cRun));
sensorValue = analogRead(BATTERY_SENSE_PIN); sensorValue = analogRead(BATTERY_SENSE_PIN);
v = sensorValue * 0.004659498; v = sensorValue * 0.004659498;
batteryPcnt = (v-3 * 100) / 1.2; batteryPcnt = (v-3.0 * 100) / 1.2;
sendBatteryLevel(batteryPcnt); sendBatteryLevel(batteryPcnt);
send(msgVolts.set(v, 2)); send(msgVolts.set(v, 2));
//} //}

View File

@@ -18,8 +18,8 @@
#define TOP_LOCK A0 #define TOP_LOCK A0
#define INT_LOCK A1 #define INT_LOCK A1
#define DOWN_LOCK A2 #define DOWN_LOCK A3
#define SMALL_LOCK A3 #define SMALL_LOCK A2
#define DOOR A4 #define DOOR A4
#define TOP_LOCK_ID 0 #define TOP_LOCK_ID 0
@@ -58,47 +58,56 @@ void presentation()
present(SMALL_LOCK_ID, S_LOCK, "Small"); present(SMALL_LOCK_ID, S_LOCK, "Small");
present(DOOR_ID, S_LOCK, "Door"); present(DOOR_ID, S_LOCK, "Door");
present(CUSTOM_ID, S_CUSTOM); present(CUSTOM_ID, S_CUSTOM);
sendData(msgDoor, digitalRead(DOOR));
wait(100);
sendData(msgTop, digitalRead(TOP_LOCK));
wait(100);
sendData(msgInt, digitalRead(INT_LOCK));
wait(100);
sendData(msgDown, digitalRead(DOWN_LOCK));
wait(100);
sendData(msgSmall, digitalRead(SMALL_LOCK));
} }
void setup() { void setup() {
// put your setup code here, to run once: bpDoor = !digitalRead(DOOR);
bpTop = !digitalRead(TOP_LOCK);
bpInt = !digitalRead(INT_LOCK);
bpSmall = !digitalRead(SMALL_LOCK);
bpDown = !digitalRead(DOWN_LOCK);
sendData(msgDoor, bpDoor);
wait(100);
sendData(msgTop, bpTop);
wait(100);
sendData(msgInt, bpInt);
wait(100);
sendData(msgDown, bpDown);
wait(100);
sendData(msgSmall, bpSmall);
} }
void loop() { void loop() {
static uint32_t cRun = millis(); static uint32_t cRun = millis();
bool bTop, bInt, bDown, bSmall, bDoor; bool bTop, bInt, bDown, bSmall, bDoor;
bTop = digitalRead(TOP_LOCK); bTop = !digitalRead(TOP_LOCK);
bInt = digitalRead(INT_LOCK); bInt = !digitalRead(INT_LOCK);
bDown = digitalRead(DOWN_LOCK); bDown = !digitalRead(DOWN_LOCK);
bSmall = digitalRead(SMALL_LOCK); bSmall = !digitalRead(SMALL_LOCK);
bDoor = digitalRead(DOOR); bDoor = !digitalRead(DOOR);
if(bTop != bpTop){ if(bTop != bpTop){
bpTop = bTop; bpTop = bTop;
sendData(msgTop, bDoor); Serial.print(F("Top Lock-"));Serial.println(bTop);
sendData(msgTop, bTop);
} }
if(bInt != bpInt){ if(bInt != bpInt){
bpInt = bInt; bpInt = bInt;
Serial.print(F("Int Lock-"));Serial.println(bInt);
sendData(msgInt, bInt); sendData(msgInt, bInt);
} }
if(bDown != bpDown){ if(bDown != bpDown){
bpDown = bDown; bpDown = bDown;
Serial.print(F("Down Lock-"));Serial.println(bDown);
sendData(msgDown, bDown); sendData(msgDown, bDown);
} }
if(bSmall != bpSmall){ if(bSmall != bpSmall){
bpSmall = bSmall; bpSmall = bSmall;
Serial.print(F("Small Lock-"));Serial.println(bSmall);
sendData(msgSmall, bSmall); sendData(msgSmall, bSmall);
} }
if(bDoor != bpDoor){ if(bDoor != bpDoor){
bpDoor = bDoor; bpDoor = bDoor;
Serial.print(F("Door-"));Serial.println(bDoor);
sendData(msgDoor, bDoor); sendData(msgDoor, bDoor);
} }
if((cRun + 29999) < millis()){ if((cRun + 29999) < millis()){