|
| 1 | +#include <Arduino.h> |
| 2 | +#include <unity.h> |
| 3 | +#include <Adafruit_NeoPixel.h> |
| 4 | + |
| 5 | +#define LED_RED 0x00FF0000 |
| 6 | +#define LED_ORANGE 0x00FF7F00 |
| 7 | +#define LED_YELLOW 0x00FFFF00 |
| 8 | +#define LED_GREEN 0x0000FF00 |
| 9 | +#define LED_BLUE 0x000000FF |
| 10 | +#define LED_INDIGO 0x004B0082 |
| 11 | +#define LED_VIOLET 0x008000FF |
| 12 | + |
| 13 | +Adafruit_NeoPixel pixels(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); |
| 14 | + |
| 15 | +void setUp(void) |
| 16 | +{ |
| 17 | + // set stuff up here |
| 18 | +} |
| 19 | + |
| 20 | +void tearDown(void) |
| 21 | +{ |
| 22 | + // clean stuff up here |
| 23 | +} |
| 24 | + |
| 25 | +void test_neopixel_pin_number(void) |
| 26 | +{ |
| 27 | + TEST_ASSERT_EQUAL(PIN_NEOPIXEL, pixels.getPin()); |
| 28 | +} |
| 29 | + |
| 30 | +void test_neopixel_state_high(void) |
| 31 | +{ |
| 32 | + uint32_t color = pixels.Color(255, 255, 255); // white color |
| 33 | + pixels.setPixelColor(0, color); |
| 34 | + pixels.show(); |
| 35 | + TEST_ASSERT_EQUAL_UINT32(color, pixels.getPixelColor(0)); |
| 36 | +} |
| 37 | + |
| 38 | +void test_neopixel_state_low(void) |
| 39 | +{ |
| 40 | + pixels.clear(); // turn off the NeoPixel |
| 41 | + pixels.show(); |
| 42 | + TEST_ASSERT_EQUAL_UINT32(pixels.Color(0, 0, 0), pixels.getPixelColor(0)); |
| 43 | +} |
| 44 | + |
| 45 | +void test_neopixel_color(uint32_t color) { |
| 46 | + pixels.setPixelColor(0, color); |
| 47 | + pixels.show(); |
| 48 | + TEST_ASSERT_EQUAL_UINT32(color, pixels.getPixelColor(0)); |
| 49 | +} |
| 50 | + |
| 51 | +void test_neopixel_colors(void) { |
| 52 | + test_neopixel_color(LED_RED); |
| 53 | + delay(500); |
| 54 | + test_neopixel_color(LED_ORANGE); |
| 55 | + delay(500); |
| 56 | + test_neopixel_color(LED_YELLOW); |
| 57 | + delay(500); |
| 58 | + test_neopixel_color(LED_GREEN); |
| 59 | + delay(500); |
| 60 | + test_neopixel_color(LED_BLUE); |
| 61 | + delay(500); |
| 62 | + test_neopixel_color(LED_INDIGO); |
| 63 | + delay(500); |
| 64 | + test_neopixel_color(LED_VIOLET); |
| 65 | + delay(500); |
| 66 | +} |
| 67 | + |
| 68 | +void setup() |
| 69 | +{ |
| 70 | + // NOTE!!! Wait for >2 secs |
| 71 | + // if board doesn't support software reset via Serial.DTR/RTS |
| 72 | + delay(2000); |
| 73 | + pixels.begin(); // This initializes the NeoPixel library. |
| 74 | + |
| 75 | + UNITY_BEGIN(); // IMPORTANT LINE! |
| 76 | + RUN_TEST(test_neopixel_pin_number); |
| 77 | +} |
| 78 | + |
| 79 | +uint8_t i = 0; |
| 80 | +uint8_t max_blinks = 3; |
| 81 | + |
| 82 | +void loop() |
| 83 | +{ |
| 84 | + if (i < max_blinks) |
| 85 | + { |
| 86 | + RUN_TEST(test_neopixel_state_high); |
| 87 | + delay(500); |
| 88 | + RUN_TEST(test_neopixel_state_low); |
| 89 | + delay(500); |
| 90 | + RUN_TEST(test_neopixel_colors); |
| 91 | + delay(500); |
| 92 | + i++; |
| 93 | + } |
| 94 | + else if (i == max_blinks) |
| 95 | + { |
| 96 | + UNITY_END(); // stop unit testing |
| 97 | + } |
| 98 | +} |
0 commit comments