Giter VIP home page Giter VIP logo

arduino-projects's People

Contributors

ruisantosdotme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

arduino-projects's Issues

Need to change Relay "Active High" to "Active Low" in Cadio Serial communication

#define CADIO_RX 20 //define custom software serial pins (SDA) (before including <CadioSerial.h>)
#define CADIO_TX 21 //define custom software serial pins (SCL) (before including <CadioSerial.h>)

#include <CadioSerial.h> //include CadioSerial library
CadioSerial cadio; //create instance

int relay[16] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 22, 23, 24, 25}; //output pins
int sw[16] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15}; //switches pins

byte swLast[16]; //for saving last switches status

void cadioOrder(int index, int value) { //new order form esp
if (value > 0) {
digitalWrite(relay[index], HIGH); //change relay status
} else {
digitalWrite(relay[index], LOW); //change relay status
}
}

void sw_check() { //check real switches changes after ignoring noise
for (int i = 0; i < 16; i++) {
if (digitalRead(sw[i]) != swLast[i]) {
bool confirm = true;
unsigned long deNoise = millis();
while (millis() - deNoise < 100) {
if (digitalRead(sw[i]) == swLast[i]) {
confirm = false;
break;
}
}
if (confirm) {
swLast[i] = digitalRead(sw[i]);
sw_changed(i);
}
}
}
}

void sw_changed(int i) { //switch status changed
digitalWrite(relay[i], !digitalRead(relay[i])); //change relay status
if (digitalRead(relay[i])) {
cadio.set(i, 255); //send new status to esp
} else {
cadio.set(i, 0); //send new status to esp
}
}

void setup() {
for (int i = 0; i < 16; i++) {
pinMode(relay[i], OUTPUT); //set relays pinMode
pinMode(sw[i], INPUT_PULLUP); //set switches pinMode
swLast[i] = digitalRead(sw[i]); //save last switches digitalRead
}
cadio.begin(); //start cadio library
cadio.onOrder(cadioOrder); //get orders
cadio.getCurrentStatus(); //request all current status from esp
}

void loop() {
sw_check(); //check switches status
cadio.loop(); //check for cadio orders
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.