init v0.1
This commit is contained in:
commit
7bf7b5f131
|
@ -0,0 +1,27 @@
|
|||
This code is released under the DWTW license
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the Do What Thou Wilt License.
|
||||
|
||||
Boundless Public License
|
||||
DO WHAT THOU WILT
|
||||
TO PUBLIC LICENSE
|
||||
|
||||
Version 2.55
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it in full or in part is allowed without any restrictions.
|
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. Do what thou wilt shall be the whole of the Law.
|
||||
|
||||
DWTWL – a license with a single requirement: DO WHAT THOU WILT
|
||||
|
||||
The license provides more freedom than any other one (such as GPL or BSD) and does not require saving the license text on copying.
|
||||
|
||||
DWTWL – an accomplished and eligible license for free text, code and any other symbols (including the software, documentation and artwork).
|
||||
|
||||
The license does not contain a "no warranty" clause. DWTWL can be used in countries that do not legally acknowledge the transition to public domain.
|
||||
|
||||
Summary:
|
||||
|
||||
An author-creator gives their source code to the world for free, without becoming distracted by worldly thinking regarding how and why the others will use it.
|
|
@ -0,0 +1,6 @@
|
|||
8-channel relay on arduino serial control with permanent led blinking
|
||||
======
|
||||
|
||||
Use 10uF capacitor for disabling autoreset on serial connection
|
||||
|
||||
![arduino-8-relay](https://dev.ussr.win/microcontrollers/arduino-8-relay/raw/branch/master/arduino-8-relay_bb.png)
|
Binary file not shown.
|
@ -0,0 +1,78 @@
|
|||
// 8-channel relay on arduino serial control with permanent led blinking
|
||||
// v0.1 under dwtwl 2.55
|
||||
// ch1 = pin2; ch2 = pin3; ch3 = pin4; ch4 = pin5;
|
||||
// ch5 = pin6; ch6 = pin7; ch7 = pin8; ch8 = pin9; led = pin13;
|
||||
// send: switch on = 1X; switch off = 2X; get status = 3X;
|
||||
// codes: in = init; eX = enabled; dX = disabled; tX = power on; fX = off;
|
||||
#include <Thread.h>
|
||||
Thread ledThread = Thread();
|
||||
|
||||
int incomingNumber = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
pinMode(13, OUTPUT);
|
||||
for(int i=2;i<10;i++){
|
||||
pinMode(i, OUTPUT);
|
||||
digitalWrite(i, HIGH);
|
||||
}
|
||||
Serial.println("in");
|
||||
|
||||
ledThread.onRun(ledBlink);
|
||||
ledThread.setInterval(1000);
|
||||
}
|
||||
|
||||
void ledBlink() {
|
||||
static bool ledStatus = false;
|
||||
ledStatus = !ledStatus;
|
||||
digitalWrite(13, ledStatus);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Thread init:
|
||||
if (ledThread.shouldRun())
|
||||
ledThread.run();
|
||||
|
||||
if (Serial.available() > 0) {
|
||||
int incomingByte = Serial.read()-48;
|
||||
if (incomingByte>=0 && incomingByte<=9) {
|
||||
incomingNumber=incomingNumber*10+incomingByte;
|
||||
} else {
|
||||
if (incomingNumber>=10 && incomingNumber<=19) {
|
||||
delay(500);
|
||||
int currentPin = incomingNumber - 9;
|
||||
char currentChannel[] = "e0";
|
||||
currentChannel[1] = '0' + (currentPin - 1);
|
||||
digitalWrite(currentPin, LOW);
|
||||
Serial.println(currentChannel);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
if (incomingNumber>=20 && incomingNumber<=29) {
|
||||
delay(500);
|
||||
int currentPin = incomingNumber - 19;
|
||||
char currentChannel[] = "d0";
|
||||
currentChannel[1] = '0' + (currentPin - 1);
|
||||
digitalWrite(currentPin, HIGH);
|
||||
Serial.println(currentChannel);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
if (incomingNumber>=30 && incomingNumber<=39) {
|
||||
delay(500);
|
||||
int currentPin = incomingNumber - 29;
|
||||
if (digitalRead(currentPin)==HIGH) {
|
||||
char currentChannel[] = "f0";
|
||||
currentChannel[1] = '0' + (currentPin - 1);
|
||||
Serial.println(currentChannel);
|
||||
} else {
|
||||
char currentChannel[] = "t0";
|
||||
currentChannel[1] = '0' + (currentPin - 1);
|
||||
Serial.println(currentChannel);
|
||||
}
|
||||
delay(500);
|
||||
}
|
||||
incomingNumber = 0;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 162 KiB |
Loading…
Reference in New Issue