Light¶
Overview¶
MoonBot Kit contains two sets of light modules,Respectively located Controller Module and Eyes Module 。 We can use Adafruit_NeoPixel library to drive these two sets of light modules.
We can drive two on-board LED lights by calling `LED’.Drive 12 LED eyes by calling `moonbot_eyes’.At the same time, through the call: ref: `LED eye movement < api-ref-led-action > ` let the eyes make a rich expression.
LED Foundation driven¶
#include <MoonBot.h>
void setup() {
// enable main control LED
LED.begin();
moonbot_eyes.begin();
// clear LED color
LED.clear();
LED.show();
moonbot_eyes.clear();
moonbot_eyes.show();
}
void loop() {
if (digitalRead(MOONBOT_PIN_BUTTON_A) == LOW
&& digitalRead(MOONBOT_PIN_BUTTON_B) == LOW) {
// If A&B is pressed at the same time
// LED and eye lights display cyan
LED.fill(0x003030);
LED.show();
moonbot_eyes.fill(0x003030);
moonbot_eyes.show();
} else if (digitalRead(MOONBOT_PIN_BUTTON_A) == LOW) {
// If key A is pressed
// LED0,The right eye display green.
LED.setPixelColor(0, 0x003000);
LED.setPixelColor(1, 0);
LED.show();
moonbot_eyes.clear();
moonbot_eyes.fill(0x003000, 0, 6);
moonbot_eyes.show();
} else if (digitalRead(MOONBOT_PIN_BUTTON_B) == LOW) {
// If key B is pressed
// LED1,The left eye display green.
LED.setPixelColor(0, 0);
LED.setPixelColor(1, 0x000030);
LED.show();
moonbot_eyes.clear();
moonbot_eyes.fill(0x000030, 6, 6);
moonbot_eyes.show();
} else {
// LED Eye lights off
LED.clear();
LED.show();
moonbot_eyes.clear();
moonbot_eyes.show();
}
}
LED Eye Lighting Action¶
MoonBot Kit provides abundant Eye action to be used:
colorWipe(moonbot_eyes, 0x40, 200); // LEDs turn green one by one
theaterChase(moonbot_eyes, 0xFF00, 50); // Eyes turn around
MoonBotEyesCircle(moonbot_eyes, 50); // Eyes turn around gradually
rainbow(moonbot_eyes, 5); // Eyes show rainbow color
rainbowCycle(moonbot_eyes, 5); // Eyes show rainbow color one by one
API Reference - Adafruit_NeoPixel¶
Check Adafruit official website for detailed information: https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use
API Reference - LED Eyes Action¶
Header File¶
Enum¶
- enum moonbot_eyes_t
eyes type
value:
- kEyesLeft
left eye
- kEyesRight
right eye
- kEyesBoth
both eyes
- enum moonbot_look_t
direction that eyes look at
value:
- kEyesLookUp
Eyes look up
- kEyesLookDown
Eyes look down
- kEyesLookLeft
Eyes look left
- kEyesLookRight
Eyes look right
- enum moonbot_eyes_scroll_t
eyes scroll type
value:
- kEyesScrollUp
eyes scroll up
- kEyesScrollDown
eyes scroll down
- kEyesScrollLeft
eyes scroll left
- kEyesScrollRight
eyes scroll right
Functions¶
- void colorFade(Adafruit_NeoPixel& led, uint8_t r, uint8_t g, uint8_t b, uint8_t wait);
LED eyes turn to target color gradually
- parameter
led
: LED typer
: value of red channelg
: value of green channelb
: value of blue channelwait
: time to wait
- void colorWipe(Adafruit_NeoPixel& led, uint32_t c, uint8_t wait);
LED change color one by one
- parameter
led
: LED typec
: REG color of the LEDwait
: time to wait for action
- void rainbow(Adafruit_NeoPixel& led, uint8_t wait);
LED light shine rainbow color
- parameter
led
: LED typewait
: time to wait
- void rainbowCycle(Adafruit_NeoPixel& led, uint8_t wait) ;
LED change light of rainbow color gradually
- parameter
led
: LED typewait
: time to wait for changing
- void theaterChase(Adafruit_NeoPixel& led, uint32_t c, uint8_t wait);
LED turn around with target color
- parameter
led
: LED typec
: RGB color of LED lightwait
: time to wait for action
- void MoonBotEyesLook(Adafruit_NeoPixel& led, moonbot_look_t look_tpye, uint32_t color);
LED eyes look to the direction
- parameter
led
: LED typelook_tpye
: the direction that eyes looks tocolor
: eyes color
- void MoonBotEyesScroll(Adafruit_NeoPixel& led, moonbot_eyes_scroll_t scroll_tpye, uint32_t color, uint8_t wait = 50);
LED eyes scroll to the direction
- parameter
led
: LED typescroll_tpye
: direction that eyes scroll tocolor
: LED color typewait
: time to wait, 50ms by default
- void MoonBotEyesCircle(Adafruit_NeoPixel& led, uint32_t color, moonbot_eyes_t eyes_type = kEyesBoth, uint8_t wait = 50);
LED eyes turn around gradually
- parameter
led
: LED typecolor
: eyes coloreyes_type
: eyes typewait
: circle time, 50ms by default