Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. void setup() {
  2.  
  3. Serial.begin(9600);
  4.  
  5. //setting button pin as input and LOW
  6.  
  7. pinMode(12, INPUT);
  8. digitalWrite(12, LOW); //DEBOUNCE relevant
  9.  
  10.  
  11. //setting input pins as output
  12.  
  13. int act_pin[6] = {A0, A1, A2, A3, A4};
  14.  
  15. int k = 0;
  16.  
  17. for (k = 0; k < 5; k++) {
  18.  
  19. pinMode(act_pin[k], OUTPUT);
  20.  
  21. }
  22.  
  23.  
  24. //setting state pins as output
  25.  
  26. int z_pin[5] = {2, 3, 4, 5};
  27.  
  28. int a = 0;
  29.  
  30. for (a = 0; a < 4; a++) {
  31.  
  32. pinMode(z_pin[a], OUTPUT);
  33.  
  34. }
  35.  
  36.  
  37. //setting output pins as output
  38.  
  39. int out_pin[6] = {9, 10, 11};
  40.  
  41. int b = 0;
  42.  
  43. for (b = 0; b < 3; b++) {
  44.  
  45. pinMode(out_pin[b], OUTPUT);
  46.  
  47. }
  48.  
  49.  
  50. //setting input
  51.  
  52. for(k = 0; k < 5; k++) {
  53.  
  54. randomSeed(analogRead(5));
  55.  
  56. int i = random(2);
  57.  
  58.  
  59. if(i == 1){
  60.  
  61. digitalWrite(act_pin[k], HIGH);
  62.  
  63. input[k] = 1;
  64.  
  65. Serial.print(input[k]);
  66.  
  67. }
  68.  
  69. else{
  70.  
  71. digitalWrite(act_pin[k], LOW);
  72.  
  73. input[k] = 0;
  74.  
  75. Serial.print(input[k]);
  76.  
  77.  
  78. }
  79.  
  80. }
  81.  
  82. //setting initial situation
  83.  
  84. digitalWrite(2, LOW);
  85. digitalWrite(3, HIGH);
  86. digitalWrite(4, LOW);
  87. digitalWrite(5, LOW);
  88.  
  89.  
  90. }
  91.  
  92. //DEBOUNCING
  93.  
  94. long lastDebounceTime = 0; // the last time the button pin was toggled
  95. long debounceDelay = 50; // the debounce time; increase if the output flickers
  96. int buttonState;
  97.  
  98. //DEBOUNCING
  99.  
  100.  
  101. boolean button_prev = 0;
  102.  
  103. boolean button = 0;
  104.  
  105. int j = 0; //value shows current lamp being processed
  106.  
  107. //setting initial state
  108.  
  109. char z[4] = "z_0";
  110.  
  111. void loop() {
  112.  
  113. button_prev = button;
  114.  
  115. button = digitalRead(8); //DEBOUNCE relevant
  116.  
  117. // DEBOUNCING
  118. if (button != button_prev) {
  119.  
  120. lastDebounceTime = millis();
  121.  
  122. }
  123.  
  124. if ((millis() - lastDebounceTime) > debounceDelay) {
  125.  
  126. if (button != button_prev) {
  127. //DEBOUNCING
  128.  
  129. if (!button_prev && button) {
  130.  
  131. int e = input[j];
  132.  
  133. //provides a nice output
  134. Serial.println(" ");
  135. Serial.print("Current lamp being processed:");
  136. Serial.println(j);
  137. Serial.println(" ");
  138. Serial.print("Current input:");
  139. Serial.println(e);
  140.  
  141.  
  142. delta(e, z);
  143.  
  144. Serial.print("State outside function:");
  145. Serial.println(z);
  146.  
  147. lamda(e, z);
  148.  
  149. j = (j+1) % 5;
  150.  
  151. }
  152.  
  153.  
  154. }
  155.  
  156. }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement