Skip to content

Commit

Permalink
test neopixel
Browse files Browse the repository at this point in the history
  • Loading branch information
zjwhitehead committed Mar 5, 2024
1 parent 64eed1f commit f7ebd26
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ board = sparkfun_promicrorp2040
framework = arduino
board_build.core = earlephilhower
build_flags = -DRP_PIO -DUSE_TINYUSB
test_framework = unity

; configure filesystem size. Default 0 Mbyte.
; Out of 16Mbyte available
Expand Down
98 changes: 98 additions & 0 deletions test/neopixel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <Arduino.h>
#include <unity.h>
#include <Adafruit_NeoPixel.h>

#define LED_RED 0x00FF0000
#define LED_ORANGE 0x00FF7F00
#define LED_YELLOW 0x00FFFF00
#define LED_GREEN 0x0000FF00
#define LED_BLUE 0x000000FF
#define LED_INDIGO 0x004B0082
#define LED_VIOLET 0x008000FF

Adafruit_NeoPixel pixels(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);

void setUp(void)
{
// set stuff up here
}

void tearDown(void)
{
// clean stuff up here
}

void test_neopixel_pin_number(void)
{
TEST_ASSERT_EQUAL(PIN_NEOPIXEL, pixels.getPin());
}

void test_neopixel_state_high(void)
{
uint32_t color = pixels.Color(255, 255, 255); // white color
pixels.setPixelColor(0, color);
pixels.show();
TEST_ASSERT_EQUAL_UINT32(color, pixels.getPixelColor(0));
}

void test_neopixel_state_low(void)
{
pixels.clear(); // turn off the NeoPixel
pixels.show();
TEST_ASSERT_EQUAL_UINT32(pixels.Color(0, 0, 0), pixels.getPixelColor(0));
}

void test_neopixel_color(uint32_t color) {
pixels.setPixelColor(0, color);
pixels.show();
TEST_ASSERT_EQUAL_UINT32(color, pixels.getPixelColor(0));
}

void test_neopixel_colors(void) {
test_neopixel_color(LED_RED);
delay(500);
test_neopixel_color(LED_ORANGE);
delay(500);
test_neopixel_color(LED_YELLOW);
delay(500);
test_neopixel_color(LED_GREEN);
delay(500);
test_neopixel_color(LED_BLUE);
delay(500);
test_neopixel_color(LED_INDIGO);
delay(500);
test_neopixel_color(LED_VIOLET);
delay(500);
}

void setup()
{
// NOTE!!! Wait for >2 secs
// if board doesn't support software reset via Serial.DTR/RTS
delay(2000);
pixels.begin(); // This initializes the NeoPixel library.

UNITY_BEGIN(); // IMPORTANT LINE!
RUN_TEST(test_neopixel_pin_number);
}

uint8_t i = 0;
uint8_t max_blinks = 3;

void loop()
{
if (i < max_blinks)
{
RUN_TEST(test_neopixel_state_high);
delay(500);
RUN_TEST(test_neopixel_state_low);
delay(500);
RUN_TEST(test_neopixel_colors);
delay(500);
i++;
}
else if (i == max_blinks)
{
UNITY_END(); // stop unit testing
}
}

0 comments on commit f7ebd26

Please sign in to comment.