Skip to main content
deleted 99 characters in body; edited title
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 18

variables Variables displayed incorretlyincorrectly

I am making a keypad and when iI try to save the buttons that were pushed they reset back to zero.

int tmp = 1;
int digit = 1;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int code = 0; 

void setup() {
  Serial.begin(9600);
  pinMode(7, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
 
}

void loop() {
  if (digit > 4) {
    digit = 1;
  }
  for (int i = 2; i <= 7; i++) {
    int tmp = digitalRead(i);
    if (tmp == HIGH) {
      if (digit == 1) {
        int a = i - 1;
 
      }
      if (digit == 2) {
        int b = i - 1;
 
      }
      if (digit == 3) {
        int c = i - 1;
 
      }
      if (digit == 4) {
        int d = i - 1;
          Serial.print(a);
          Serial.print(b);
          Serial.print(c);
          Serial.print(d);
 
          digitalWrite(8, HIGH);
          
   
      }

 
      
      digitalWrite(9, HIGH);
      delay(100);
      digitalWrite(9, LOW);
      delay(100);
      Serial.print(i);
      digit++;
 
    }
  }
}

variables displayed incorretly

I am making a keypad and when i try to save the buttons that were pushed they reset back to zero.

int tmp = 1;
int digit = 1;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int code = 0;
void setup() {
  Serial.begin(9600);
  pinMode(7, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
 
}

void loop() {
  if (digit > 4) {
    digit = 1;
  }
  for (int i = 2; i <= 7; i++) {
    int tmp = digitalRead(i);
    if (tmp == HIGH) {
      if (digit == 1) {
        int a = i - 1;
 
      }
      if (digit == 2) {
        int b = i - 1;
 
      }
      if (digit == 3) {
        int c = i - 1;
 
      }
      if (digit == 4) {
        int d = i - 1;
          Serial.print(a);
          Serial.print(b);
          Serial.print(c);
          Serial.print(d);
 
          digitalWrite(8, HIGH);
          
   
      }

 
      
      digitalWrite(9, HIGH);
      delay(100);
      digitalWrite(9, LOW);
      delay(100);
      Serial.print(i);
      digit++;
 
    }
  }
}

Variables displayed incorrectly

I am making a keypad and when I try to save the buttons that were pushed they reset back to zero.

int tmp = 1;
int digit = 1;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int code = 0; 

void setup() {
  Serial.begin(9600);
  pinMode(7, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
}

void loop() {
  if (digit > 4) {
    digit = 1;
  }
  for (int i = 2; i <= 7; i++) {
    int tmp = digitalRead(i);
    if (tmp == HIGH) {
      if (digit == 1) {
        int a = i - 1;
      }
      if (digit == 2) {
        int b = i - 1;
      }
      if (digit == 3) {
        int c = i - 1;
      }
      if (digit == 4) {
        int d = i - 1;
        Serial.print(a);
        Serial.print(b);
        Serial.print(c);
        Serial.print(d);
        digitalWrite(8, HIGH);
      }
      digitalWrite(9, HIGH);
      delay(100);
      digitalWrite(9, LOW);
      delay(100);
      Serial.print(i);
      digit++;
    }
  }
}
Source Link

variables displayed incorretly

I am making a keypad and when i try to save the buttons that were pushed they reset back to zero.

int tmp = 1;
int digit = 1;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int code = 0;
void setup() {
  Serial.begin(9600);
  pinMode(7, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);

}

void loop() {
  if (digit > 4) {
    digit = 1;
  }
  for (int i = 2; i <= 7; i++) {
    int tmp = digitalRead(i);
    if (tmp == HIGH) {
      if (digit == 1) {
        int a = i - 1;

      }
      if (digit == 2) {
        int b = i - 1;

      }
      if (digit == 3) {
        int c = i - 1;
 
      }
      if (digit == 4) {
        int d = i - 1;
          Serial.print(a);
          Serial.print(b);
          Serial.print(c);
          Serial.print(d);

          digitalWrite(8, HIGH);
          
   
      }


      
      digitalWrite(9, HIGH);
      delay(100);
      digitalWrite(9, LOW);
      delay(100);
      Serial.print(i);
      digit++;

    }
  }
}