No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unabkraft.ino 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /******************************************************************************\
  2. * author : serguei_chmod77 (Arthur) *
  3. * codename : unabkraft *
  4. * testing board : unab77 *
  5. * processor : at(mel)mega 328p *
  6. * date : 07.08.2015 *
  7. * version : 1.5.2 ``Boolzor powered'' *
  8. * compiler : avrdude, OpenBSD 5.6 *
  9. \******************************************************************************/
  10. // Id of digital-pins by nicknames :
  11. const int pushButt = 2;
  12. const int ledBarA = 3, ledBarB = 4, ledBarC = 5, ledBarD = 6, ledBarE = 7;
  13. const int ledBarF = 8, ledBarG = 9, ledBarH = 10, ledBarI = 11;
  14. const int mainLed = 12, bell = 13;
  15. // Some integer variables for arithmetical counts along loop() :
  16. int i = 2000, k = 0, pb = 0, lb = 0, s = 0;
  17. int lastDebounceTime = 0;
  18. long ctDownSet = 0, dc = 0, cd = 0;
  19. bool zor = true, modeState = false;
  20. void defusing() {
  21. zor = false;
  22. }
  23. void setup(void) {
  24. // Pins input/output mode global setting :
  25. pinMode(mainLed, OUTPUT);
  26. pinMode(ledBarA, OUTPUT);
  27. pinMode(ledBarB, OUTPUT);
  28. pinMode(ledBarC, OUTPUT);
  29. pinMode(ledBarD, OUTPUT);
  30. pinMode(ledBarE, OUTPUT);
  31. pinMode(ledBarF, OUTPUT);
  32. pinMode(ledBarG, OUTPUT);
  33. pinMode(ledBarH, OUTPUT);
  34. pinMode(ledBarI, OUTPUT);
  35. pinMode(bell, OUTPUT);
  36. pinMode(pushButt, INPUT);
  37. attachInterrupt(0, defusing, CHANGE);
  38. }
  39. void thisIsTheEnd() {
  40. i = 2000;
  41. while (i >= 400) {
  42. if (zor) {
  43. k=i/2;
  44. s = i - 50;
  45. digitalWrite(mainLed, HIGH);
  46. digitalWrite(bell, HIGH);
  47. delay(50);
  48. digitalWrite(bell, LOW);
  49. delay(s);
  50. digitalWrite(mainLed, LOW);
  51. delay(k);
  52. i -= k;
  53. }
  54. else {
  55. goto lastStraw;
  56. }
  57. }
  58. while (i >= 20) {
  59. if (zor) {
  60. digitalWrite(mainLed, HIGH);
  61. digitalWrite(bell, HIGH);
  62. delay(i);
  63. digitalWrite(mainLed, LOW);
  64. digitalWrite(bell, LOW);
  65. delay(i);
  66. i -= 10;
  67. }
  68. else {
  69. goto lastStraw;
  70. }
  71. }
  72. i = 2000;
  73. // Chenillard final
  74. lb = 3;
  75. while (lb < 12) {
  76. digitalWrite(lb, HIGH);
  77. delay(400);
  78. lb ++;
  79. }
  80. delay(500);
  81. lb = 3;
  82. while (lb < 12) {
  83. digitalWrite(lb, LOW);
  84. lb ++;
  85. }
  86. lb = 3;
  87. digitalWrite(bell, HIGH);
  88. while (lb < 12) {
  89. digitalWrite(lb, HIGH);
  90. delay(100);
  91. digitalWrite(lb, LOW);
  92. lb ++;
  93. }
  94. lb = 10;
  95. while (lb > 2) {
  96. digitalWrite(lb, HIGH);
  97. delay(100);
  98. digitalWrite(lb, LOW);
  99. lb --;
  100. }
  101. zor = true;
  102. lastStraw:
  103. digitalWrite(bell, LOW);
  104. }
  105. void initConditions() {
  106. delay(300); // interruption debounce, else it'll jump the 'while'
  107. lb = 3;
  108. while ( lb < 12 ) {
  109. digitalWrite(lb, LOW);
  110. lb ++;
  111. }
  112. ctDownSet = 0;
  113. k = 0;
  114. dc = 0;
  115. lastDebounceTime = 0;
  116. modeState = false;
  117. }
  118. /* ========================================================================== */
  119. void loop(void) {
  120. clearSelect:
  121. initConditions();
  122. while ( modeState == false ) {
  123. if ( ctDownSet < 2700001 ) {
  124. k=ctDownSet/300000 + 2;
  125. digitalWrite(k, HIGH);
  126. if ( digitalRead(pushButt) == LOW ) {
  127. lastDebounceTime = millis();
  128. delay(300); // debounce
  129. // check if the switch is pressed for a long time
  130. if( digitalRead(pushButt) == LOW && ( lastDebounceTime - millis() ) > 5000 ) {
  131. modeState = true;
  132. i=0;
  133. while( i<2 ) {
  134. digitalWrite(bell, HIGH);
  135. delay(200);
  136. digitalWrite(bell, LOW);
  137. delay(200);
  138. i++;
  139. }
  140. delay(700);
  141. goto sayByBye;
  142. }
  143. // otherwise (short pressure), just increment the countdown delay
  144. else {
  145. ctDownSet += 300000;
  146. digitalWrite(mainLed, HIGH);
  147. delay(300);
  148. digitalWrite(mainLed, LOW);
  149. }
  150. }
  151. }
  152. else {
  153. goto clearSelect;
  154. }
  155. }
  156. sayByBye:
  157. zor = true;
  158. if (zor) {
  159. if ( ctDownSet != 0 ) {
  160. k=ctDownSet/300000;
  161. while ( k > 1 ) {
  162. //delay(300000);
  163. dc = 0;
  164. countDown:
  165. while ( dc < 300001 ) {
  166. if (zor) {
  167. delay(10);
  168. dc += 10;
  169. }
  170. else {
  171. i = 0;
  172. while ( i < 2 ) {
  173. digitalWrite(mainLed, HIGH);
  174. delay(300);
  175. digitalWrite(mainLed, LOW);
  176. delay(300);
  177. i ++;
  178. }
  179. cd = 0;
  180. while ( cd < 10001 ) {
  181. delay(10);
  182. cd += 10;
  183. }
  184. zor = true;
  185. delay(400);
  186. if (zor) {
  187. i = 0;
  188. while ( i < 2 ) {
  189. digitalWrite(mainLed, HIGH);
  190. delay(300);
  191. digitalWrite(mainLed, LOW);
  192. delay(300);
  193. i ++;
  194. }
  195. goto countDown;
  196. }
  197. else {
  198. goto jackFlash;
  199. }
  200. }
  201. }
  202. digitalWrite(k+2, LOW);
  203. digitalWrite(k+1, HIGH);
  204. k --;
  205. }
  206. dc = 0;
  207. takeFive:
  208. while ( dc < 300001 ) {
  209. if (zor) {
  210. delay(10);
  211. dc += 10;
  212. }
  213. else {
  214. i = 0;
  215. while ( i < 2 ) {
  216. digitalWrite(mainLed, HIGH);
  217. delay(300);
  218. digitalWrite(mainLed, LOW);
  219. delay(300);
  220. i ++;
  221. }
  222. cd = 0;
  223. while ( cd < 10001 ) {
  224. delay(10);
  225. cd += 10;
  226. }
  227. zor = true;
  228. delay(400);
  229. if (zor) {
  230. i = 0;
  231. while ( i < 2 ) {
  232. digitalWrite(mainLed, HIGH);
  233. delay(300);
  234. digitalWrite(mainLed, LOW);
  235. delay(300);
  236. i ++;
  237. }
  238. goto takeFive;
  239. }
  240. else {
  241. goto jackFlash;
  242. }
  243. }
  244. }
  245. digitalWrite(3, LOW);
  246. }
  247. }
  248. jackFlash:
  249. if (zor) {
  250. thisIsTheEnd();
  251. if ( zor == false ) {
  252. k = 11;
  253. while ( k > 2 ) {
  254. digitalWrite(k, HIGH);
  255. k --;
  256. }
  257. k = 9;
  258. goto defuseSign;
  259. }
  260. }
  261. else {
  262. defuseSign:
  263. lb = k + 2;
  264. while ( lb > 2 ) {
  265. digitalWrite(bell, HIGH);
  266. digitalWrite(lb, LOW);
  267. delay(500 - lb*25);
  268. digitalWrite(bell, LOW);
  269. delay(200 - lb*15);
  270. lb --;
  271. }
  272. }
  273. return;
  274. }