commit 7bf7b5f13106527067fbfb800afd891fa66202d3 Author: zlaxy Date: Sun Dec 2 23:24:07 2018 +0300 init v0.1 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ed09b19 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..25b4ad7 --- /dev/null +++ b/README.md @@ -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) diff --git a/arduino-8-relay.fzz b/arduino-8-relay.fzz new file mode 100644 index 0000000..cf664dd Binary files /dev/null and b/arduino-8-relay.fzz differ diff --git a/arduino-8-relay.ino b/arduino-8-relay.ino new file mode 100644 index 0000000..56bd1b0 --- /dev/null +++ b/arduino-8-relay.ino @@ -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 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; + } + } +} diff --git a/arduino-8-relay_bb.png b/arduino-8-relay_bb.png new file mode 100644 index 0000000..bb36521 Binary files /dev/null and b/arduino-8-relay_bb.png differ