Π ΡΠ΅Π³ΠΎΠ΄Π½ΡΡΠ½Π΅ΠΉ ΡΡΠ°ΡΡΠ΅ Ρ ΠΎΡΡ ΠΏΠΎΠ΄Π΅Π»ΠΈΡΡΡ Ρ Π²Π°ΠΌΠΈ Π½ΠΎΠ²ΡΠΌ ΠΏΡΠΎΠ΅ΠΊΡΠΎΠΌ. ΠΠ° ΡΡΠΎΡ ΡΠ°Π· ΡΡΠΎ ΡΠ΅Π½ΡΠΎΡΠ½ΡΠΉ Π²ΡΠΊΠ»ΡΡΠ°ΡΠ΅Π»Ρ Ρ ΡΡΠ΅ΠΊΠ»ΡΠ½Π½ΠΎΠΉ ΠΏΠ°Π½Π΅Π»ΡΡ. Π£ΡΡΡΠΎΠΉΡΡΠ²ΠΎ ΠΊΠΎΠΌΠΏΠ°ΠΊΡΠ½ΠΎΠ΅, ΡΠ°Π·ΠΌΠ΅ΡΠ°ΠΌΠΈ 42Ρ 42ΠΌΠΌ(ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΡΠ΅ ΡΡΠ΅ΠΊΠ»ΡΠ½Π½ΡΠ΅ ΠΏΠ°Π½Π΅Π»Ρ ΠΈΠΌΠ΅Π΅Ρ ΡΠ°Π·ΠΌΠ΅ΡΡ 80Ρ 80ΠΌΠΌ). ΠΡΡΠΎΡΠΈΡ ΡΡΠΎΠ³ΠΎ ΡΡΡΡΠΎΠΉΡΡΠ²Π° Π½Π°ΡΠ°Π»Π°ΡΡ Π΄Π°Π²Π½ΠΎ, ΠΎΠΊΠΎΠ»ΠΎ Π³ΠΎΠ΄Π° Π½Π°Π·Π°Π΄.
ΠΡΠ΅Π²ΡΠ΅ Π²Π°ΡΠΈΠ°Π½ΡΡ Π±ΡΠ»ΠΈ Π½Π° ΠΌΠΈΠΊΡΠΎΠΊΠΎΠ½ΡΡΠΎΠ»Π΅ΡΠ΅ atmega328, Π½ΠΎ Π² ΠΈΡΠΎΠ³Π΅ Π²ΡΠ΅ Π·Π°ΠΊΠΎΠ½ΡΠΈΠ»ΠΎΡΡ ΠΌΠΈΠΊΡΠΎΠΊΠΎΠ½ΡΡΠΎΠ»Π΅ΡΠΎΠΌ nRF52832.
Π‘Π΅Π½ΡΠΎΡΠ½Π°Ρ ΡΠ°ΡΡΡ ΡΡΡΡΠΎΠΉΡΡΠ²Π° ΡΠ°Π±ΠΎΡΠ°Π΅Ρ Π½Π° ΠΌΠΈΠΊΡΠΎΡΡ
Π΅ΠΌΠ°Ρ
TTP223. ΠΠ±Π° ΡΠ΅Π½ΡΠΎΡΠ° ΠΎΠ±ΡΠ»ΡΠΆΠΈΠ²Π°Π΅Ρ ΠΎΠ΄Π½ΠΎ ΠΏΡΠ΅ΡΡΠ²Π°Π½ΠΈΠ΅. ΠΠΈΡΠ°Π½ΠΈΠ΅ ΠΎΡ Π±Π°ΡΠ°ΡΠ΅ΠΉΠΊΠΈ CR2477, ΡΠ΅ΡΠ΅Π· ΠΏΠΎΠ²ΡΡΠ°ΡΡΠΈΠΉ ΠΏΡΠ΅ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°ΡΠ΅Π»Ρ Π½Π° ΠΌΠΈΠΊΡΠΎΡΡ
Π΅ΠΌΠ΅ TPS610981 |
Π ΡΡΡΡΠΎΠΉΡΡΠ²Π΅ ΡΠ΅Π°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π° ΡΡ Π΅ΠΌΠ° ΠΎΡΠΊΠ»ΡΡΠ΅Π½ΠΈΡ ΠΏΠΈΡΠ°Π½ΠΈΡ Π½Π° ΠΏΠΎΠ»Π΅Π²ΡΡ ΡΡΠ°Π½Π·ΠΈΡΡΠΎΡΠ°Ρ . ΠΠΎΡΠ»Π΅ Π½Π°ΠΆΠ°ΡΠΈΡ Π½Π° ΠΊΠ½ΠΎΠΏΠΊΡ ΠΌΠΈΠΊΡΠΎΠΊΠΎΠ½ΡΡΠΎΠ»Π΅Ρ ΡΠ°ΠΌ ΠΏΠ΅ΡΠ΅Ρ Π²Π°ΡΡΠ²Π°Π΅Ρ ΡΠΏΡΠ°Π²Π»Π΅Π½ΠΈΠ΅ ΠΏΠΈΡΠ°Π½ΠΈΠ΅ΠΌ ΠΈ Π΄Π°Π»Π΅Π΅ ΠΊΠ½ΠΎΠΏΠΊΠ° ΠΌΠΎΠΆΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡΡ Π΄Π»Ρ ΡΠ΅ΡΠ²ΠΈΡΠ½ΡΡ ΡΠ΅ΠΆΠΈΠΌΠΎΠ²(Π² ΠΌΠΎΠ΅ΠΌ ΡΠ»ΡΡΠ°Π΅Ρ ΡΡΠΎ ΡΠΎΠΏΡΡΠΆΠ΅Π½ΠΈΠ΅ Ρ Π΄ΡΡΠ³ΠΈΠΌΠΈ ΡΡΡΡΠΎΠΉΡΡΠ²Π°ΠΌΠΈ, ΠΎΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΠΏΠΈΡΠ°Π½ΠΈΡ ΠΈ ΡΠ±ΡΠΎΡ ΠΊ Π·Π°Π²ΠΎΠ΄ΡΠΊΠΈΠΌ ΡΡΡΠ°Π½ΠΎΠ²ΠΊΠ°ΠΌ(factory reset)).
ΠΡΠΈΡΡΡΡΡΠ²ΡΡΡ 2 rgb ΡΠ²Π΅ΡΠΎΠ΄ΠΈΠΎΠ΄Π° Π΄Π»Ρ ΠΈΠ½Π΄ΠΈΠΊΠ°ΡΠΈΠΉ ΡΠΎΡΡΠΎΡΠ½ΠΈΠΉ ΠΈ ΡΠ΅ΡΠ²ΠΈΡΠ½ΡΡ
ΡΠ΅ΠΆΠΈΠΌΠΎΠ². Π’Π°ΠΊ ΠΆΠ΅ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ ΠΏΡΠ΅Π·ΠΎΠΈΠ·Π»ΡΡΠ°ΡΠ΅Π»Ρ Π΄Π»Ρ ΠΈΠΌΠΈΡΠ°ΡΠΈΠΈ ΠΊΠ»ΠΈΠΊΠ° ΠΏΡΠΈ ΠΏΡΠΈΠΊΠΎΡΠ½ΠΎΠ²Π΅Π½ΠΈΠΈ ΠΊ ΡΠ΅Π½ΡΠΎΡΠ½ΡΠΌ ΠΊΠ½ΠΎΠΏΠΊΠ°ΠΌ ΠΈ Π·Π²ΡΠΊΠΎΠ²ΠΎΠΉ ΠΈΠ½Π΄ΠΈΠΊΠ°ΡΠΈΠΈ ΡΠ΅ΡΠ²ΠΈΡΠ½ΡΡ
ΡΠ΅ΠΆΠΈΠΌΠΎΠ². Π‘Π²Π΅ΡΠΎΠ΄ΠΈΠΎΠ΄Ρ ΠΈ ΠΏΡΠ΅Π·ΠΎΠΈΠ·Π»ΡΡΠ°ΡΠ΅Π»Ρ ΠΌΠΎΠΆΠ½ΠΎ Π²ΠΊΠ»ΡΡΠ°ΡΡ ΠΈ ΠΎΡΠΊΠ»ΡΡΠ°ΡΡ ΠΏΠΎ ΠΆΠ΅Π»Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ. ΠΠ΅Π»Π°Π΅ΡΡΡ ΡΡΠΎ ΡΠ΅ΡΠ΅Π· ΠΊΠΎΠ½ΡΡΠΎΠ»Π΅Ρ ΡΠΌΠ½ΠΎΠ³ΠΎ Π΄ΠΎΠΌΠ°, ΠΎΡΠΏΡΠ°Π²ΠΊΠΎΠΉ ΠΊΠΎΠΌΠ°Π½Π΄ Π½Π° ΡΠ΅Ρ
Π½ΠΈΡΠ΅ΡΠΊΠΈΠ΅ ΡΠ΅Π½ΡΠΎΡΡ, ΡΠ°ΠΊ ΠΆΠ΅ ΡΠ΅Π°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΡ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Π΅ΠΌ ΠΈΠ½ΡΠ΅ΡΠ²Π°Π»ΠΎΠ² ΠΎΡΠΏΡΠ°Π²ΠΊΠΈ Π·Π°ΡΡΠ΄Π° Π±Π°ΡΠ°ΡΠ΅ΠΈ ΠΈ ΡΡΠΎΠ²Π½Ρ ΡΠΈΠ³Π½Π°Π»Π° ΡΠ°ΠΊ ΠΆΠ΅ ΡΠ΅ΡΠ΅Π· ΠΊΠΎΠ½ΡΡΠΎΠ»Π΅Ρ ΡΠΌΠ½ΠΎΠ³ΠΎ Π΄ΠΎΠΌΠ°. Π ΠΌΠΎΠ΅ΠΌ ΡΠ»ΡΡΠ°Π΅ ΡΡΠΎ
ΠΠΎΡΡΠ΅Π±Π»Π΅Π½ΠΈΠ΅ Π² ΡΠ΅ΠΆΠΈΠΌΠ΅ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΠΈ 7ΠΌΠ(250ΠΊΠ±ΠΈΡ, 10ΠΌΡ), ΠΏΠΎΡΡΠ΅Π±Π»Π΅Π½ΠΈΠ΅ Π²ΠΎ ΡΠ½Π΅ 40ΠΌΠΊΠ, ΠΏΠΎΡΡΠ΅Π±Π»Π΅Π½ΠΈΠ΅ Π² Π²ΡΠΊΠ»ΡΡΠ΅Π½Π½ΠΎΠΌ ΡΠΎΡΡΠΎΡΠ½ΠΈΠΈ ΠΌΠ΅Π½Π΅Π΅ 1ΠΌΠΊΠ(=ΠΏΠΎΡΡΠ΅Π±Π»Π΅Π½ΠΈΡ ΠΏΠΎΠ²ΡΡΠ°ΡΡΠ΅Π³ΠΎ ΠΏΡΠ΅ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°ΡΠ΅Π»Ρ Π² Β«Ρ ΠΎΠ»ΠΎΡΡΠΎΠΌΒ» ΡΠ΅ΠΆΠΈΠΌΠ΅). ΠΡΠ²Π΅Π΄Π΅Π½ rx, tx, swd ΡΠ°Π·ΡΠ΅ΠΌ Π΄Π»Ρ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΡ. ΠΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΡΡΡ ΠΌΠΈΠ½ΠΈΠ°ΡΡΡΠ½ΡΠΉ ΡΠ°Π·ΡΠ΅ΠΌ 2Ρ 3p Ρ ΡΠ°Π³ΠΎΠΌ 1.27. ΠΠ»Ρ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΡ ΠΈΠ·Π³ΠΎΡΠΎΠ²Π»Π΅Π½ ΡΠΏΠ΅ΡΠΈΠ°Π»ΡΠ½ΡΠΉ ΠΏΠ΅ΡΠ΅Ρ ΠΎΠ΄Π½ΠΈΠΊ.
ΠΠ°ΠΊ ΠΈ Π²ΡΠ΅Π³Π΄Π° Π² ΠΎΡΠ½ΠΎΠ²Π΅ ΡΠ°Π±ΠΎΡΡ ΡΡΡΡΠΎΠΉΡΡΠ²Π° Π»Π΅ΠΆΠΈΡ ΠΏΡΠΎΡΠΎΠΊΠΎΠ»
ΠΠΎΡΠΏΡΡ ΠΏΠΎ ΡΡΠ°Π΄ΠΈΡΠΈΠΈ ΠΏΠ΅ΡΠ°ΡΠ°Π»ΡΡ Π½Π° SLA ΠΏΡΠΈΠ½ΡΠ΅ΡΠ΅, ΡΡΡΡΠΎΠΉΡΡΠ²ΠΎ ΠΌΠΈΠ½ΠΈΠ°ΡΡΡΠ½ΠΎΠ΅, ΠΊΠΎΡΠΏΡΡ ΠΏΠΎΠ»ΡΡΠΈΠ»ΡΡ Π½Π΅Π±ΠΎΠ»ΡΡΠΎΠΉ, ΠΏΡΠΈΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ Π΄Π°Π½ΠΎΠΉ ΡΠ΅Ρ Π½ΠΎΠ»ΠΎΠ³ΠΈΠΈ ΠΏΠ΅ΡΠ°ΡΠΈ ΠΎΠΏΡΠ°Π²Π΄Π°Π½ΠΎ.
ΠΠΎΡΠΌΠΎΡΡΠ΅ΡΡ ΠΎΡΠΏΠ΅ΡΠ°ΡΠ°Π½Π½ΡΡ ΠΌΠΎΠ΄Π΅Π»Ρ
Π ΠΊΠΎΡΠΏΡΡ ΠΈ ΠΊΡΡΡΠΊΡ Π±Π°ΡΠ°ΡΠ΅ΠΉΠ½ΠΎΠ³ΠΎ ΠΎΡΡΠ΅ΠΊΠ° Π²ΠΊΠ»Π΅Π΅Π½Ρ ΠΌΠ°Π³Π½ΠΈΡΠΈΠΊΠΈ.
ΠΠΈΠ΄ΠΎΡΠΈΠΊΠΈ Ρ ΡΠ΅ΡΡΠ°ΠΌΠΈ Π΄Π°Π½Π½ΠΎΠ³ΠΎ ΡΡΡΡΡΠΎΠΉΡΡΠ²Π°:
ΠΠ»Ρ ΠΆΠ΅Π»Π°ΡΡΠΈΡ ΠΏΠΎΠ²ΡΠΎΡΠΈΡΡ:
ΠΠΎΠ΄ ΡΠ΅ΡΡΠΎΠ²ΠΎΠΉ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ Π²ΡΠΊΠ»ΡΡΠ°ΡΠ΅Π»Ρ Π² ΡΠΈΡΡΠ΅ΠΌΠ΅ ΡΠΏΡΠ°Π²Π»Π΅Π½ΠΈΡ ΡΡΠ»ΠΎΠ½Π½ΡΠΌΠΈ ΡΡΠΎΡΠ°ΠΌΠΈ Π΄Π»Ρ Arduino IDE
ΠΡΠ΄ΡΠΈΠ½ΠΎ ΠΠΈΡΠΈΠ½Π³
int8_t timer_status = 0;
boolean sens_flag1 = 0;
boolean sens_flag2 = 0;
boolean switch_a = 0;
boolean switch_b = 0;
uint16_t temp;
float vcc;
int battery;
int old_battery;
uint32_t oldmillis;
uint32_t newmillis;
uint32_t interrupt_time;
uint32_t SLEEP_TIME = 7000;
uint32_t SLEEP_TIME_W;
uint32_t SLEEP_TIME_W2;
int NrfRSSI;
uint16_t NrfRSSI2;
boolean wait_off;
//#define MY_DEBUG
#define MY_DISABLED_SERIAL
#define MY_RADIO_NRF5_ESB
#define MY_PASSIVE_NODE
#define MY_NODE_ID 120
#define MY_PARENT_NODE_ID 0
#define MY_PARENT_NODE_IS_STATIC
#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
#define POWER_CHILD_ID 110
#define UP_POWER_SWITCH_ID 1
#define DOWN_POWER_SWITCH_ID 2
#define CHILD_ID_nRF52_RSSI_RX 3
#define BAT_COOF 0.0092957746478873
#define BAT_MIN 200
#define BAT_MAX 290
#include <MySensors.h>
MyMessage upMsg(UP_POWER_SWITCH_ID, V_STATUS);
MyMessage downMsg(DOWN_POWER_SWITCH_ID, V_STATUS);
MyMessage powerMsg(POWER_CHILD_ID, V_VAR1);
MyMessage msgRF52RssiReceiv(CHILD_ID_nRF52_RSSI_RX, V_VAR1);
void preHwInit() {
pinMode(31, OUTPUT); //power management pin
digitalWrite(31, HIGH);
delay(3000);
pinMode(3, INPUT); // on off mode button
pinMode(25, OUTPUT); // sens1 led
pinMode(26, OUTPUT); // sens1 led
pinMode(27, OUTPUT); // sens1 led
pinMode(6, OUTPUT); // sens21 led
pinMode(7, OUTPUT); // sens2 led
pinMode(8, OUTPUT); // sens2 led
pinMode(28, OUTPUT); // bizzer
pinMode(2, INPUT); // common interrupt for touch sensors
pinMode(9, INPUT); // touch sensors1
pinMode(10, INPUT); //touch sensors2
pinMode(29, INPUT); // battery
digitalWrite(28, LOW);
digitalWrite(27, HIGH);
digitalWrite(26, HIGH);
digitalWrite(25, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}
void before()
{
NRF_POWER->DCDCEN = 1;
analogReadResolution(12);
disableNfc();
turnOffAdc();
digitalWrite(25, LOW);
digitalWrite(6, LOW);
wait(200);
digitalWrite(25, HIGH);
digitalWrite(6, HIGH);
wait(100);
playSound0();
wait(100);
digitalWrite(25, LOW);
digitalWrite(6, LOW);
wait(200);
digitalWrite(25, HIGH);
digitalWrite(6, HIGH);
wait(3000);
digitalWrite(27, LOW);
digitalWrite(8, LOW);
wait(200);
digitalWrite(27, HIGH);
digitalWrite(8, HIGH);
wait(400);
digitalWrite(6, LOW);
digitalWrite(25, LOW);
wait(200);
digitalWrite(6, HIGH);
digitalWrite(25, HIGH);
wait(400);
digitalWrite(26, LOW);
digitalWrite(7, LOW);
wait(200);
digitalWrite(26, HIGH);
digitalWrite(7, HIGH);
wait(1000);
digitalWrite(26, LOW);
digitalWrite(7, LOW);
}
void setup()
{
digitalWrite(26, HIGH);
digitalWrite(7, HIGH);
wait(50);
playSound();
wait(2000);
readBatLev();
wait(200);
SLEEP_TIME_W = SLEEP_TIME;
}
void presentation()
{
sendSketchInfo("EFEKTA ON|OFF NODE 2CH", "1.0");
wait(100);
present(POWER_CHILD_ID, S_CUSTOM, "BATTERY DATA");
wait(100);
present(UP_POWER_SWITCH_ID, S_BINARY, "UP SWITCH");
wait(100);
present(DOWN_POWER_SWITCH_ID, S_BINARY, "DOWN SWITCH");
}
void loop()
{
if (sens_flag1 == 0 && sens_flag2 == 0) {
if (switch_a == 0 && switch_b == 0) {
timer_status = sleep(digitalPinToInterrupt(2), RISING, digitalPinToInterrupt(3), RISING, 3600000, false);
wait_off = 1;
} else {
//oldmillis = millis();
timer_status = sleep(digitalPinToInterrupt(2), RISING, digitalPinToInterrupt(3), RISING, SLEEP_TIME_W, false);
wait_off = 0;
}
}
if (timer_status == 3) {
wait(100);
digitalWrite(27, LOW);
digitalWrite(8, LOW);
wait(2000);
digitalWrite(27, HIGH);
digitalWrite(8, HIGH);
wait(100);
digitalWrite(31, LOW);
}
if (timer_status == 2) {
if (digitalRead(9) == HIGH && sens_flag1 == 0 && switch_b == 0) {
sens_flag1 = 1;
if (switch_a == 0) {
oldmillis = millis();
SLEEP_TIME_W = SLEEP_TIME;
switch_a = 1;
digitalWrite(6, LOW);
wait(10);
playSound1();
wait(20);
playSound2();
wait(50);
send(upMsg.set(switch_a));
wait(200);
} else {
switch_a = 0;
digitalWrite(6, HIGH);
wait(10);
playSound2();
wait(20);
playSound1();
wait(50);
send(upMsg.set(switch_a));
wait(200);
}
}
if (digitalRead(10) == HIGH && sens_flag2 == 0 && switch_a == 0) {
sens_flag2 = 1;
if (switch_b == 0) {
oldmillis = millis();
SLEEP_TIME_W = SLEEP_TIME;
switch_b = 1;
digitalWrite(25, LOW);
wait(10);
playSound1();
wait(20);
playSound2();
wait(50);
send(downMsg.set(switch_b));
wait(200);
} else {
switch_b = 0;
digitalWrite(25, HIGH);
wait(10);
playSound2();
wait(20);
playSound1();
wait(50);
send(downMsg.set(switch_b));
wait(200);
}
}
if (digitalRead(9) == LOW && sens_flag1 == 1) {
sens_flag1 = 0;
}
if (digitalRead(10) == LOW && sens_flag2 == 1) {
sens_flag2 = 0;
}
if (switch_a == 1 || switch_b == 1) {
if (wait_off == 0) {
newmillis = millis();
wait(10);
SLEEP_TIME_W2 = SLEEP_TIME_W;
wait(10);
interrupt_time = newmillis - oldmillis;
wait(10);
SLEEP_TIME_W = SLEEP_TIME_W2 - interrupt_time;
wait(10);
Serial.print("WAS IN A SLEEP: ");
Serial.print(newmillis - oldmillis);
Serial.println(" MILLISECONDS");
if (SLEEP_TIME_W < 1000) {
if (switch_a == 1) {
switch_a = 0;
digitalWrite(6, HIGH);
wait(10);
playSound2();
wait(20);
playSound1();
wait(50);
send(upMsg.set(switch_a));
wait(200);
}
if (switch_b == 1) {
switch_b = 0;
digitalWrite(25, HIGH);
wait(10);
playSound2();
wait(20);
playSound1();
wait(50);
send(downMsg.set(switch_b));
wait(200);
}
SLEEP_TIME_W = SLEEP_TIME;
wait(50);
}
Serial.println(SLEEP_TIME);
Serial.println(SLEEP_TIME_W);
Serial.println(SLEEP_TIME_W2);
Serial.print("GO TO SLEEP FOR: ");
Serial.print(SLEEP_TIME_W);
Serial.println(" MILLISECONDS");
}
oldmillis = millis();
}
}
if (timer_status == -1) {
if (switch_a == 1 || switch_b == 1) {
if (switch_a == 1) {
switch_a = 0;
digitalWrite(6, HIGH);
wait(10);
playSound2();
wait(20);
playSound1();
wait(50);
send(upMsg.set(switch_a));
wait(200);
}
if (switch_b == 1) {
switch_b = 0;
digitalWrite(25, HIGH);
wait(10);
playSound2();
wait(20);
playSound1();
wait(50);
send(downMsg.set(switch_b));
wait(200);
}
} else {
readBatLev();
}
}
}
void disableNfc() {
NRF_NFCT->TASKS_DISABLE = 1;
NRF_NVMC->CONFIG = 1;
NRF_UICR->NFCPINS = 0;
NRF_NVMC->CONFIG = 0;
}
void turnOffAdc() {
if (NRF_SAADC->ENABLE) {
NRF_SAADC->TASKS_STOP = 1;
while (NRF_SAADC->EVENTS_STOPPED) {}
NRF_SAADC->ENABLE = 0;
while (NRF_SAADC->ENABLE) {}
}
}
void myTone(uint32_t j, uint32_t k) {
j = 500000 / j;
k += millis();
while (k > millis()) {
digitalWrite(28, HIGH); delayMicroseconds(j);
digitalWrite(28, LOW ); delayMicroseconds(j);
}
}
void playSound0() {
myTone(1300, 50);
wait(20);
myTone(1300, 50);
wait(50);
}
void playSound() {
myTone(700, 30);
wait(10);
myTone(700, 30);
wait(10);
myTone(700, 30);
wait(50);
}
void playSound1() {
myTone(200, 10);
wait(10);
myTone(400, 5);
wait(30);
}
void playSound2() {
myTone(400, 10);
wait(10);
myTone(200, 5);
wait(30);
}
void readBatLev() {
temp = analogRead(29);
vcc = temp * 0.0033 * 100;
battery = map((int)vcc, BAT_MIN, BAT_MAX, 0, 100);
if (battery < 0) {
battery = 0;
}
if (battery > 100) {
battery = 100;
}
sendBatteryLevel(battery, 1);
wait(2000, C_INTERNAL, I_BATTERY_LEVEL);
send(powerMsg.set(temp));
wait(200);
NrfRSSI = transportGetReceivingRSSI();
NrfRSSI2 = map(NrfRSSI, -85, -40, 0, 100);
if (NrfRSSI2 < 0) {
NrfRSSI2 = 0;
}
if (NrfRSSI2 > 100) {
NrfRSSI2 = 100;
}
send(msgRF52RssiReceiv.set(NrfRSSI2));
wait(200);
}
Π€Π°ΠΉΠ»Ρ ΠΊΠΎΡΠΏΡΡΠ° Π² stl β
Gerber ΡΠ°ΠΉΠ»Ρ ΠΏΠ΅ΡΠ°ΡΠ½ΠΎΠΉ ΠΏΠ»Π°ΡΡ β
ΠΠ° Π²ΠΎΠΏΡΠΎΡΡ ΠΏΠΎ Π΄Π°Π½Π½ΠΎΠΉ ΡΠ°Π·ΡΠ°Π±ΠΎΡΠΊΠ΅, ΠΏΠΎ ΡΡΡΠ΄Π½ΠΎΡΡΡΠΌ Π² Π²Π°ΡΠΈΡ
ΡΠ°Π·ΡΠ°Π±ΠΎΡΠΊΠ°Ρ
Π½Π° Π°ΡΠ΄ΡΠΈΠ½ΠΊΠ°Ρ
ΠΈ Mysensors Π²ΡΠ΅Π³Π΄Π° ΠΏΡΠΈΠ΄ΡΡ Π½Π° ΠΏΠΎΠΌΠΎΡΡ Π² Π½Π°ΡΠ΅ΠΌ ΡΠ΅Π»Π΅Π³ΡΠ°ΠΌΠΌ ΡΠ°ΡΠ΅ β
ΠΡΡΠΎΡΠ½ΠΈΠΊ: habr.com