vencinachev

Arduino AND Tester

Jan 13th, 2026 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. const int A_PIN = 13;  // вход A към чипа
  2. const int B_PIN = 12;  // вход B към чипа
  3. const int Y_PIN = 11;  // изход от чипа към Arduino
  4. const int LED_OK = 4;
  5. const int LED_NOK = 8;
  6.  
  7. struct Vec {
  8.   uint8_t a;
  9.   uint8_t b;
  10.   uint8_t expected;
  11. };
  12.  
  13. Vec tests[] = {
  14.   {0, 0, 0},
  15.   {0, 1, 0},
  16.   {1, 0, 0},
  17.   {1, 1, 1}
  18. };
  19.  
  20. void setup() {
  21.   Serial.begin(115200);
  22.  
  23.   pinMode(A_PIN, OUTPUT);
  24.   pinMode(B_PIN, OUTPUT);
  25.   pinMode(Y_PIN, INPUT);
  26.   pinMode(LED_OK, OUTPUT);
  27.   pinMode(LED_NOK, OUTPUT);
  28.   Serial.println("74HC AND tester start");
  29.   bool pass = true;
  30.  
  31.   for (int i = 0; i < 4; i++) {
  32.     digitalWrite(A_PIN, tests[i].a);
  33.     digitalWrite(B_PIN, tests[i].b);
  34.  
  35.     delayMicroseconds(10); // време за установяване
  36.  
  37.     int y = digitalRead(Y_PIN);
  38.  
  39.     if (y != tests[i].expected) {
  40.       pass = false;
  41.       Serial.print("FAIL: A=");
  42.       Serial.print(tests[i].a);
  43.       Serial.print(" B=");
  44.       Serial.print(tests[i].b);
  45.       Serial.print(" -> Y=");
  46.       Serial.print(y);
  47.       Serial.print(" expected ");
  48.       Serial.println(tests[i].expected);
  49.     }
  50.   }
  51.  
  52.   if (pass){
  53.     Serial.println("PASS: gate OK");
  54.     digitalWrite(LED_OK, HIGH);
  55.   } else {
  56.     Serial.println("Fail: NOK");
  57.     digitalWrite(LED_NOK, HIGH);
  58.   }
  59. }
  60.  
  61. void loop() {
  62. }
Advertisement
Add Comment
Please, Sign In to add comment