Asystent AI
Proszę o informację...
 
Powiadomienia
Wyczyść wszystko

Proszę o informację lub kod do Arduino Mega jak zrobic aby w Domoticzu był widziany tylko jako np: 16 wejść i 32

1 Wpisów
1 Użytkownicy
0 Reactions
1,566 Wyświetleń
(@gruszfil)
Wpisów: 1
Świeżak
Autor tematu
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 
[#2380]

Witam wszystkich jestem nowym członkiem szanownego grona forumowiczów.

Proszę o informację lub kod do Arduino Mega jak zrobic aby w Domoticzu był widziany tylko jako np: 16 wejść i 32 wyjścia lecz sterowany tylko z poziomu Domoticza. Przykładowo Wciskam przycisk A0 Domoticz dostaje informacje a nastepnie wykonuje zaprogramowaną akcję np włącza wyjście 31 w Arduino Mega. Generalnie chodzi mi o to, aby nie przypisywać w kodzie (jak po niżej) danego wejścia do wyjścia.

Z góry dziekuję. 

 

Podaje kod do Arduino Mega z przypisanymi wejściami od A0 - A15 do wyjść od 22 - 37 z raportowaniem do Domoticza jak by się nie chciało komuś klepać:

 

// Enable debug prints to serial monitor
#define MY_DEBUG

// Enable and select radio type attached
//#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69

// Set LOW transmit power level as default, if you have an amplified NRF-module and
// power your radio separately with a good regulator you can turn up PA level.
//#define MY_RF24_PA_LEVEL RF24_PA_LOW

// Enable serial gateway
#define MY_GATEWAY_SERIAL

// Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
#if F_CPU == 8000000L
#define MY_BAUD_RATE 38400
#endif

// Flash leds on rx/tx/err
// #define MY_LEDS_BLINKING_FEATURE
// Set blinking period
// #define MY_DEFAULT_LED_BLINK_PERIOD 300

// Inverses the behavior of leds
// #define MY_WITH_LEDS_BLINKING_INVERSE

// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
#define MY_INCLUSION_BUTTON_FEATURE

// Inverses behavior of inclusion button (if using external pullup)
//#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP

// Set inclusion mode duration (in seconds)
#define MY_INCLUSION_MODE_DURATION 60
// Digital pin used for inclusion mode button
#define MY_INCLUSION_MODE_BUTTON_PIN 3

// Uncomment to override default HW configurations
//#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
//#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin
//#define MY_DEFAULT_TX_LED_PIN 5 // the PCB, on board LED

#include
#include
#include

// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE

#define RELAY_1 22 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define RELAY_2 23
#define RELAY_3 24
#define RELAY_4 25
#define RELAY_5 26
#define RELAY_6 27
#define RELAY_7 28
#define RELAY_8 29
#define RELAY_9 30
#define RELAY_10 31
#define RELAY_11 32
#define RELAY_12 33
#define RELAY_13 34
#define RELAY_14 35
#define RELAY_15 36
#define RELAY_16 37
#define RELAY_17 38
#define RELAY_18 39
#define RELAY_19 40
#define RELAY_20 41
#define RELAY_21 42
#define RELAY_22 43
#define RELAY_23 44
#define RELAY_24 45
#define RELAY_25 46
#define RELAY_26 47
#define RELAY_27 48
#define RELAY_28 49
#define RELAY_29 50
#define RELAY_30 51
#define RELAY_31 52
#define RELAY_32 53

#define NUMBER_OF_RELAYS 32 // Total number of attached relays
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay

#define BUTTON_PIN A0
#define BUTTON2_PIN A1
#define BUTTON3_PIN A2
#define BUTTON4_PIN A3
#define BUTTON5_PIN A4
#define BUTTON6_PIN A5
#define BUTTON7_PIN A6
#define BUTTON8_PIN A7
#define BUTTON9_PIN A8
#define BUTTON10_PIN A9
#define BUTTON11_PIN A10
#define BUTTON12_PIN A11
#define BUTTON13_PIN A12
#define BUTTON14_PIN A13
#define BUTTON15_PIN A14
#define BUTTON16_PIN A15

void before() {
for (int sensor = 1, pin = RELAY_1; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
digitalWrite(pin, loadState(sensor) ? RELAY_ON : RELAY_OFF);
}
}
Bounce debouncer = Bounce();
Bounce debouncer2 = Bounce();
Bounce debouncer3 = Bounce();
Bounce debouncer4 = Bounce();
Bounce debouncer5 = Bounce();
Bounce debouncer6 = Bounce();
Bounce debouncer7 = Bounce();
Bounce debouncer8 = Bounce();
Bounce debouncer9 = Bounce();
Bounce debouncer10 = Bounce();
Bounce debouncer11 = Bounce();
Bounce debouncer12 = Bounce();
Bounce debouncer13 = Bounce();
Bounce debouncer14 = Bounce();
Bounce debouncer15 = Bounce();
Bounce debouncer16 = Bounce();

void setup() {
// Setup locally attached sensors
delay(10000);
// Setup the button.
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(BUTTON2_PIN, INPUT_PULLUP);
pinMode(BUTTON3_PIN, INPUT_PULLUP);
pinMode(BUTTON4_PIN, INPUT_PULLUP);
pinMode(BUTTON5_PIN, INPUT_PULLUP);
pinMode(BUTTON6_PIN, INPUT_PULLUP);
pinMode(BUTTON7_PIN, INPUT_PULLUP);
pinMode(BUTTON8_PIN, INPUT_PULLUP);
pinMode(BUTTON9_PIN, INPUT_PULLUP);
pinMode(BUTTON10_PIN, INPUT_PULLUP);
pinMode(BUTTON11_PIN, INPUT_PULLUP);
pinMode(BUTTON12_PIN, INPUT_PULLUP);
pinMode(BUTTON13_PIN, INPUT_PULLUP);
pinMode(BUTTON14_PIN, INPUT_PULLUP);
pinMode(BUTTON15_PIN, INPUT_PULLUP);
pinMode(BUTTON16_PIN, INPUT_PULLUP);

// After setting up the button, setup debouncer.
debouncer.attach(BUTTON_PIN);
debouncer.interval(5);
debouncer2.attach(BUTTON2_PIN);
debouncer2.interval(5);
debouncer3.attach(BUTTON3_PIN);
debouncer3.interval(5);
debouncer4.attach(BUTTON4_PIN);
debouncer4.interval(5);
debouncer5.attach(BUTTON5_PIN);
debouncer5.interval(5);
debouncer6.attach(BUTTON6_PIN);
debouncer6.interval(5);
debouncer7.attach(BUTTON7_PIN);
debouncer7.interval(5);
debouncer8.attach(BUTTON8_PIN);
debouncer8.interval(5);
debouncer9.attach(BUTTON9_PIN);
debouncer9.interval(5);
debouncer10.attach(BUTTON10_PIN);
debouncer10.interval(5);
debouncer11.attach(BUTTON11_PIN);
debouncer11.interval(5);
debouncer12.attach(BUTTON12_PIN);
debouncer12.interval(5);
debouncer13.attach(BUTTON13_PIN);
debouncer13.interval(5);
debouncer14.attach(BUTTON14_PIN);
debouncer14.interval(5);
debouncer15.attach(BUTTON15_PIN);
debouncer15.interval(5);
debouncer16.attach(BUTTON16_PIN);
debouncer16.interval(5);

//presentation();
}
void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Relay", "1.0");

for (int sensor = 1, pin = RELAY_1; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
// Register all sensors to gw (they will be created as child devices)
present(sensor, S_LIGHT);
}
}

MyMessage msg(1, V_LIGHT);
MyMessage msg2(2, V_LIGHT);
MyMessage msg3(3, V_LIGHT);
MyMessage msg4(4, V_LIGHT);
MyMessage msg5(5, V_LIGHT);
MyMessage msg6(6, V_LIGHT);
MyMessage msg7(7, V_LIGHT);
MyMessage msg8(8, V_LIGHT);
MyMessage msg9(9, V_LIGHT);
MyMessage msg10(10, V_LIGHT);
MyMessage msg11(11, V_LIGHT);
MyMessage msg12(12, V_LIGHT);
MyMessage msg13(13, V_LIGHT);
MyMessage msg14(14, V_LIGHT);
MyMessage msg15(15, V_LIGHT);
MyMessage msg16(16, V_LIGHT);
MyMessage msg17(17, V_LIGHT);
MyMessage msg18(18, V_LIGHT);
MyMessage msg19(19, V_LIGHT);
MyMessage msg20(20, V_LIGHT);
MyMessage msg21(21, V_LIGHT);
MyMessage msg22(22, V_LIGHT);
MyMessage msg23(23, V_LIGHT);
MyMessage msg24(24, V_LIGHT);
MyMessage msg25(25, V_LIGHT);
MyMessage msg26(26, V_LIGHT);
MyMessage msg27(27, V_LIGHT);
MyMessage msg28(28, V_LIGHT);
MyMessage msg29(29, V_LIGHT);
MyMessage msg30(30, V_LIGHT);
MyMessage msg31(31, V_LIGHT);
MyMessage msg32(32, V_LIGHT);

void loop() {
// Send locally attached sensor data here
if (debouncer.update()) {
// Get the update value.
int value = debouncer.read();
// Send in the new value.
if (value == LOW) {
saveState(1, !loadState(1));
digitalWrite(RELAY_1, loadState(1) ? RELAY_ON : RELAY_OFF);
send(msg.set(loadState(1)));
}
}
if (debouncer2.update()) {
int value2 = debouncer2.read();
if (value2 == LOW) {
saveState(2, !loadState(2));
digitalWrite(RELAY_2, loadState(2) ? RELAY_ON : RELAY_OFF);
send(msg2.set(loadState(2)));
}
}
if (debouncer3.update()) {
int value3 = debouncer3.read();
if (value3 == LOW) {
saveState(3, !loadState(3));
digitalWrite(RELAY_3, loadState(4) ? RELAY_ON : RELAY_OFF);
send(msg3.set(loadState(3)));
}
}
if (debouncer4.update()) {
int value4 = debouncer4.read();
if (value4 == LOW) {
saveState(4, !loadState(4));
digitalWrite(RELAY_4, loadState(4) ? RELAY_ON : RELAY_OFF);
send(msg4.set(loadState(4)));
}
}
if (debouncer5.update()) {
int value5 = debouncer5.read();
if (value5 == LOW) {
saveState(5, !loadState(5));
digitalWrite(RELAY_5, loadState(5) ? RELAY_ON : RELAY_OFF);
send(msg5.set(loadState(5)));
}
}
if (debouncer6.update()) {
int value6 = debouncer6.read();
if (value6 == LOW) {
saveState(6, !loadState(6));
digitalWrite(RELAY_6, loadState(6) ? RELAY_ON : RELAY_OFF);
send(msg6.set(loadState(6)));
}
}
if (debouncer7.update()) {
int value7 = debouncer7.read();
if (value7 == LOW) {
saveState(7, !loadState(7));
digitalWrite(RELAY_7, loadState(7) ? RELAY_ON : RELAY_OFF);
send(msg7.set(loadState(7)));
}
}
if (debouncer8.update()) {
int value8 = debouncer8.read();
if (value8 == LOW) {
saveState(8, !loadState(8));
digitalWrite(RELAY_8, loadState(8) ? RELAY_ON : RELAY_OFF);
send(msg8.set(loadState(8)));
}
}
if (debouncer9.update()) {
int value9 = debouncer9.read();
if (value9 == LOW) {
saveState(9, !loadState(9));
digitalWrite(RELAY_9, loadState(9) ? RELAY_ON : RELAY_OFF);
send(msg9.set(loadState(9)));
}
}
if (debouncer10.update()) {
int value10 = debouncer10.read();
if (value10 == LOW) {
saveState(10, !loadState(10));
digitalWrite(RELAY_10, loadState(10) ? RELAY_ON : RELAY_OFF);
send(msg10.set(loadState(10)));
}
}
if (debouncer11.update()) {
int value11 = debouncer11.read();
if (value11 == LOW) {
saveState(11, !loadState(11));
digitalWrite(RELAY_11, loadState(11) ? RELAY_ON : RELAY_OFF);
send(msg11.set(loadState(3)));
}
}
if (debouncer12.update()) {
int value12 = debouncer12.read();
if (value12 == LOW) {
saveState(12, !loadState(12));
digitalWrite(RELAY_12, loadState(12) ? RELAY_ON : RELAY_OFF);
send(msg12.set(loadState(12)));
}
}
if (debouncer13.update()) {
int value13 = debouncer13.read();
if (value13 == LOW) {
saveState(13, !loadState(13));
digitalWrite(RELAY_13, loadState(13) ? RELAY_ON : RELAY_OFF);
send(msg13.set(loadState(13)));
}
}
if (debouncer14.update()) {
int value14 = debouncer14.read();
if (value14 == LOW) {
saveState(14, !loadState(14));
digitalWrite(RELAY_14, loadState(14) ? RELAY_ON : RELAY_OFF);
send(msg14.set(loadState(14)));
}
}
if (debouncer15.update()) {
int value15 = debouncer15.read();
if (value15 == LOW) {
saveState(15, !loadState(15));
digitalWrite(RELAY_15, loadState(15) ? RELAY_ON : RELAY_OFF);
send(msg15.set(loadState(15)));
}
}
if (debouncer16.update()) {
int value16 = debouncer16.read();
if (value16 == LOW) {
saveState(16, !loadState(16));
digitalWrite(RELAY_16, loadState(16) ? RELAY_ON : RELAY_OFF);
send(msg16.set(loadState(16)));
}
}

}

void receive(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type == V_LIGHT) {
// Change relay state
digitalWrite(message.sensor - 1 + RELAY_1, message.getBool() ? RELAY_ON : RELAY_OFF);
// Store state in eeprom
saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}


 
Dodane : 15/11/2020 6:36 pm
Udostępnij: