Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup() {
- Serial.begin(9600);
- //setting button pin as input and LOW
- pinMode(12, INPUT);
- digitalWrite(12, LOW); //DEBOUNCE relevant
- //setting input pins as output
- int act_pin[6] = {A0, A1, A2, A3, A4};
- int k = 0;
- for (k = 0; k < 5; k++) {
- pinMode(act_pin[k], OUTPUT);
- }
- //setting state pins as output
- int z_pin[5] = {2, 3, 4, 5};
- int a = 0;
- for (a = 0; a < 4; a++) {
- pinMode(z_pin[a], OUTPUT);
- }
- //setting output pins as output
- int out_pin[6] = {9, 10, 11};
- int b = 0;
- for (b = 0; b < 3; b++) {
- pinMode(out_pin[b], OUTPUT);
- }
- //setting input
- for(k = 0; k < 5; k++) {
- randomSeed(analogRead(5));
- int i = random(2);
- if(i == 1){
- digitalWrite(act_pin[k], HIGH);
- input[k] = 1;
- Serial.print(input[k]);
- }
- else{
- digitalWrite(act_pin[k], LOW);
- input[k] = 0;
- Serial.print(input[k]);
- }
- }
- //setting initial situation
- digitalWrite(2, LOW);
- digitalWrite(3, HIGH);
- digitalWrite(4, LOW);
- digitalWrite(5, LOW);
- }
- //DEBOUNCING
- long lastDebounceTime = 0; // the last time the button pin was toggled
- long debounceDelay = 50; // the debounce time; increase if the output flickers
- int buttonState;
- //DEBOUNCING
- boolean button_prev = 0;
- boolean button = 0;
- int j = 0; //value shows current lamp being processed
- //setting initial state
- char z[4] = "z_0";
- void loop() {
- button_prev = button;
- button = digitalRead(8); //DEBOUNCE relevant
- // DEBOUNCING
- if (button != button_prev) {
- lastDebounceTime = millis();
- }
- if ((millis() - lastDebounceTime) > debounceDelay) {
- if (button != button_prev) {
- //DEBOUNCING
- if (!button_prev && button) {
- int e = input[j];
- //provides a nice output
- Serial.println(" ");
- Serial.print("Current lamp being processed:");
- Serial.println(j);
- Serial.println(" ");
- Serial.print("Current input:");
- Serial.println(e);
- delta(e, z);
- Serial.print("State outside function:");
- Serial.println(z);
- lamda(e, z);
- j = (j+1) % 5;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement