Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int A_PIN = 13; // вход A към чипа
- const int B_PIN = 12; // вход B към чипа
- const int Y_PIN = 11; // изход от чипа към Arduino
- const int LED_OK = 4;
- const int LED_NOK = 8;
- struct Vec {
- uint8_t a;
- uint8_t b;
- uint8_t expected;
- };
- Vec tests[] = {
- {0, 0, 0},
- {0, 1, 0},
- {1, 0, 0},
- {1, 1, 1}
- };
- void setup() {
- Serial.begin(115200);
- pinMode(A_PIN, OUTPUT);
- pinMode(B_PIN, OUTPUT);
- pinMode(Y_PIN, INPUT);
- pinMode(LED_OK, OUTPUT);
- pinMode(LED_NOK, OUTPUT);
- Serial.println("74HC AND tester start");
- bool pass = true;
- for (int i = 0; i < 4; i++) {
- digitalWrite(A_PIN, tests[i].a);
- digitalWrite(B_PIN, tests[i].b);
- delayMicroseconds(10); // време за установяване
- int y = digitalRead(Y_PIN);
- if (y != tests[i].expected) {
- pass = false;
- Serial.print("FAIL: A=");
- Serial.print(tests[i].a);
- Serial.print(" B=");
- Serial.print(tests[i].b);
- Serial.print(" -> Y=");
- Serial.print(y);
- Serial.print(" expected ");
- Serial.println(tests[i].expected);
- }
- }
- if (pass){
- Serial.println("PASS: gate OK");
- digitalWrite(LED_OK, HIGH);
- } else {
- Serial.println("Fail: NOK");
- digitalWrite(LED_NOK, HIGH);
- }
- }
- void loop() {
- }
Advertisement
Add Comment
Please, Sign In to add comment