esref_21

Arduino & CS:GO, Arduino Code For Tens Device

Nov 7th, 2016
155
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------------------------------------TRANSLATED TO ENGLISH FOR INSTRUCTABLES------------------------------------
  2. /*
  3. Relay IN2 -> to Pin 7
  4. Relay IN1 -> to Pin 6
  5.  
  6. digitalWrite'ta 0 command; Opens the relay and current current passes to right of middle pod(tested and achieved this result)
  7.  
  8. The cables (green one) out of the "ON" to Q2(right relay), Off (pink cable) to Q1(left).
  9.  
  10. Commands:
  11. "0" - Cuts Off The Electricity
  12. "+" - Increase the selected mode (+1)
  13. "-" - Reduce the selected mode (-1)
  14. */
  15. int RelayPinOn = 7;
  16. int RelayPinOff = 6;
  17. int Level = 0;
  18. boolean IsStarted = false;
  19. void setup()
  20. {
  21. Serial.begin(57600);
  22. pinMode(RelayPinOn, OUTPUT);
  23. pinMode(RelayPinOff, OUTPUT);
  24. digitalWrite(RelayPinOn,1);
  25. CutOffElectric(10,50);
  26. Serial.println("Before you start read the instructions below!\n Little mistake can cause Noron Disease, Death Or Paralysis");
  27. Serial.println("----------------------------------------------");
  28. Serial.println("Just in case, device is shutting down\n");
  29. Serial.println("ATTENTION: If the mod has changed manually\n that resetting will be meanless.\n\n Remove battery from device before opening Serial Monitor. \n Plug the batteries again, Start the COM without touching anything\nThen push the Mode button twice");
  30. Serial.println("----------------------------------------------\n\n");
  31. Serial.println("----------Commands---------------");
  32. Serial.println("+ : Increase the selected mode");
  33. Serial.println("- : Reduce the selected mode");
  34. Serial.println("0 : Close Device");
  35. Serial.println("---------------------------------\n\n");
  36. delay (100);
  37. OpenDevice();
  38. Serial.println("--------System Started--------");
  39. Serial.println("Device Opened, Not Giving Electricity Yet");
  40. }
  41.  
  42. void loop()
  43. {
  44. int getValue = Serial.read();
  45. switch (getValue)
  46. {
  47. case '+':
  48. Increase();
  49. break;
  50. case '-':
  51. Reduce();
  52. break;
  53.  
  54. case '0':
  55. Serial.println("Cutted of electiricity");
  56. CutOffElectric(10,50);
  57. break;
  58.  
  59. }
  60. }
  61. void CutOffElectric(int HowManyTime,int BetweenTime)
  62. {
  63. for (int sayi = 1; sayi <= HowManyTime; sayi++)
  64. {
  65. digitalWrite(RelayPinOff,0);
  66. delay (BetweenTime);
  67. digitalWrite(RelayPinOff,1);
  68. delay (BetweenTime);
  69. }
  70. Level = 0;
  71. IsStarted = false;
  72. OpenDevice();
  73. }
  74. void OpenDevice()
  75. {
  76. digitalWrite(RelayPinOn,0);
  77. delay (100);
  78. digitalWrite(RelayPinOn,1);
  79. }
  80. void Increase()
  81. {
  82. Level +=1;
  83. Serial.println("Increased 1");
  84. digitalWrite(RelayPinOn,0);
  85. delay (50);
  86. digitalWrite(RelayPinOn,1);
  87. IsStarted = true;
  88. }
  89. void Reduce()
  90. {
  91. Level -=1;
  92. if (Level >= 1)
  93. {
  94. Serial.println("Reduced 1");
  95. digitalWrite(RelayPinOff,0);
  96. delay (50);
  97. digitalWrite(RelayPinOff,1);
  98. }
  99. if (IsStarted == false)
  100. {
  101. Serial.println("There is nothing to reduce because of not started yet");
  102. Level = 0;
  103. }
  104. if (Level <= 0 && IsStarted == true)
  105. {
  106. Serial.println("Achieved to Minimum Level");
  107. Level = 1;
  108. }
  109. }
  110.  
  111. ---------------------------------------------------------------------------------------------------------------
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. ------------------------------------ORIGINAL CODE------------------------------------
  120. /*
  121. Röle IN2 -> Pin 7'ye
  122. Röle IN1 -> Pin 6'ya
  123.  
  124. digitalWrite'ta 0 komudu Röleyi açar ve orta ayağın sağından akım geçer(test ederek bu sonuca varıldı...)
  125.  
  126. On'dan çıkan yeşil kablolar Q2(kabloların takıldığı yerdeki yazılara göre sağdaki röle)'ye, Off'tan çıkan pembe lablolar Q1(sol) rölesine bağlanır.
  127. Kabloların bir ucu orta ayağa, diğer ucu kabloların takıldığı yerdeki yazılara göre) sağ ayağa.
  128.  
  129. Komutlar:
  130. "0" - Elektriği Keser
  131. "+" - Seçili Olan Modu 1 Arttirir
  132. "-" - Seçili Olan Modu 1 Azaltir
  133. */
  134. int RolePinAc = 7;
  135. int RolePinKapa = 6;
  136. int Derece = 0;
  137. boolean BaslandiMi = false;
  138. void setup()
  139. {
  140. Serial.begin(57600);
  141. pinMode(RolePinAc, OUTPUT);
  142. pinMode(RolePinKapa, OUTPUT);
  143. digitalWrite(RolePinAc,1);
  144. ElektrigiKes(10,50);
  145. Serial.println("Baslamadan Once Yonergeleri Dikkatlice Oku!\nEn Kucuk Bir Hata Noron Hastaliklari,Olum Veya Felce Yol Acabilir");
  146. Serial.println("----------------------------------------------");
  147. Serial.println("Garantiye Almak Icin Once Cihaz Kapaniyor\n");
  148. Serial.println("DIKKAT: Eger Mod Manuel Olarak Degistirilmisse\nBu Sifirlama Etki Etmeyecektir\n\nSeri Monitoru Acmadan Once Cihazin Pilini Cikar.\nCihazin Pilini Tak, Hicbir Seye Dokunmadan COM'u Ac\nSonra Iki Kere Mode Butonuna Bas");
  149. Serial.println("----------------------------------------------\n\n");
  150. Serial.println("----------Komutlar---------------");
  151. Serial.println("+ : 1 Secili Olan Modu 1 Arttirir");
  152. Serial.println("- : 1 Secili Olan Modu 1 Azaltir");
  153. Serial.println("0 : 1 Cihazi Kapatir");
  154. Serial.println("---------------------------------\n\n");
  155. delay (100);
  156. CihaziAc();
  157. Serial.println("--------Sistem Baslatildi--------");
  158. Serial.println("Cihaz Acildi, Elektrik Verilmiyor");
  159. }
  160.  
  161. void loop()
  162. {
  163. int gelenDeger = Serial.read();
  164. switch (gelenDeger)
  165. {
  166. case '+':
  167. Arttir();
  168. break;
  169. case '-':
  170. Azalt();
  171. break;
  172.  
  173. case '0':
  174. Serial.println("Elektrigi Keser");
  175. ElektrigiKes(10,50); // 10 kere tetik [aç-kapa yap] ve 50ms aralığında
  176. break;
  177.  
  178. }
  179. }
  180. void ElektrigiKes(int KacKere,int ZamanAraligi)
  181. {
  182. for (int sayi = 1; sayi <= KacKere; sayi++)
  183. {
  184. digitalWrite(RolePinKapa,0);
  185. delay (ZamanAraligi);
  186. digitalWrite(RolePinKapa,1);
  187. delay (ZamanAraligi);
  188. }
  189. Derece = 0;
  190. BaslandiMi = false;
  191. CihaziAc();
  192. }
  193. void CihaziAc()
  194. {
  195. digitalWrite(RolePinAc,0);
  196. delay (100);
  197. digitalWrite(RolePinAc,1);
  198. }
  199. void Arttir()
  200. {
  201. Derece +=1;
  202. Serial.println("1 Arttirildi");
  203. digitalWrite(RolePinAc,0); // orta ayağın bi sağından tetik ver, 50 ms sonra röleyi kapat
  204. delay (50);
  205. digitalWrite(RolePinAc,1);
  206. BaslandiMi = true;
  207. }
  208. void Azalt()
  209. {
  210. Derece -=1;
  211. if (Derece >= 1)
  212. {
  213. Serial.println("1 Azaltildi");
  214. digitalWrite(RolePinKapa,0);
  215. delay (50);
  216. digitalWrite(RolePinKapa,1);
  217. }
  218. if (BaslandiMi == false)
  219. {
  220. Serial.println("Henuz Baslanmadigi Icin Azaltilacak Bir Sey Yok");
  221. Derece = 0;
  222. }
  223. if (Derece <= 0 && BaslandiMi == true)
  224. {
  225. Serial.println("Minimum Degere Ulasildi");
  226. Derece = 1;
  227. }
  228. }
  229.  
  230. -------------------------------------------------------------------------------------
RAW Paste Data