|
2 | 2 | #include <unity.h>
|
3 | 3 |
|
4 | 4 | #define BTN 0
|
| 5 | +#define LED 4 |
5 | 6 |
|
6 |
| -void test_button() { |
7 |
| - Serial.println("Button test"); |
8 |
| - static int count = 0; |
9 |
| - static int lastState = HIGH; |
10 |
| - while (count < 3) { |
11 |
| - int state = digitalRead(BTN); |
12 |
| - if (state != lastState) { |
13 |
| - if (state == LOW) { |
14 |
| - count++; |
15 |
| - Serial.print("Button pressed "); |
16 |
| - Serial.print(count); |
17 |
| - Serial.println(" times"); |
18 |
| - } |
19 |
| - lastState = state; |
20 |
| - } |
21 |
| - delay(10); |
22 |
| - } |
| 7 | +void setUp(void) {} |
| 8 | + |
| 9 | +void tearDown(void) {} |
| 10 | + |
| 11 | +void test_read_basic(void) { |
| 12 | + Serial.println("GPIO read - basic START"); |
| 13 | + |
| 14 | + pinMode(BTN, INPUT_PULLUP); |
| 15 | + assert(digitalRead(BTN) == 1); |
| 16 | + TEST_ASSERT_EQUAL(HIGH, digitalRead(BTN)); |
| 17 | + Serial.println("BTN read as HIGH after pinMode INPUT_PULLUP"); |
| 18 | + |
| 19 | + delay(1000); |
| 20 | + TEST_ASSERT_EQUAL(LOW, digitalRead(BTN)); |
| 21 | + Serial.println("BTN read as LOW"); |
| 22 | + |
| 23 | + delay(1000); |
| 24 | + TEST_ASSERT_EQUAL(HIGH, digitalRead(BTN)); |
| 25 | + Serial.println("BTN read as HIGH"); |
| 26 | +} |
| 27 | + |
| 28 | +void test_write_basic(void) { |
| 29 | + Serial.println("GPIO write - basic test"); |
| 30 | + pinMode(LED, OUTPUT); |
| 31 | + delay(1000); |
| 32 | + Serial.println("GPIO LED set to OUTPUT"); |
| 33 | + delay(2000); |
| 34 | + |
| 35 | + digitalWrite(LED, HIGH); |
| 36 | + delay(1000); |
| 37 | + Serial.println("LED set to HIGH"); |
| 38 | + |
| 39 | + delay(3000); |
| 40 | + digitalWrite(LED, LOW); |
| 41 | + Serial.println("LED set to LOW"); |
23 | 42 | }
|
24 | 43 |
|
| 44 | + |
25 | 45 | void setup() {
|
26 | 46 | Serial.begin(115200);
|
27 |
| - pinMode(BTN, INPUT_PULLUP); |
28 |
| - test_button(); |
| 47 | + while (!Serial) { |
| 48 | + ; |
| 49 | + } |
| 50 | + |
| 51 | + UNITY_BEGIN(); |
| 52 | + RUN_TEST(test_read_basic); |
| 53 | + RUN_TEST(test_write_basic); |
| 54 | + UNITY_END(); |
| 55 | + |
| 56 | + Serial.println("GPIO test END"); |
29 | 57 | }
|
30 | 58 |
|
31 | 59 | void loop() {}
|
0 commit comments