ruisantosdotme / arduino-projects Goto Github PK
View Code? Open in Web Editor NEWRNT Arduino Projects
Home Page: http://randomnerdtutorials.com/
RNT Arduino Projects
Home Page: http://randomnerdtutorials.com/
#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
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.