42
STEP2:
Connect Crowtail-Button and Crowtail-9G Servo to Crowtail-Base shield’s D5 and D6 port.
Connect Crowtail-LED Matrix to Crowtail-Base shield’s I port. The complete connection is as follows:
Open the
P20_Polite_Automatic_Door
with Arduino IDE and upload it.
Upload the program, when you press the button, the servo will rotate to 180 degrees(open door) and
LED Matrix will show “Welcome” prompt message. When you release the button, the servo will rotate
back to 0 degrees(close door). LED Matrix no longer prompts.
What will you see
1. Import the I2C, LED Matrix and servo library.
2. Create instances of LED Matrix and servo.
3. Declare variables of button’s pin and state.
4. Initialize the LED Matrix and servo, pass the I2C address to LED Matrix and declare the pin of servo.
5. Read the state of the button.
6. If button is pressed, LED Matrix displays the welcome message and servo rotate to 180 degrees.
7. If button is not pressed, LED Matrix will display nothing and servo rotate to 0 degrees.
Code overview
Switch case statement: switch(variable){case constantExpression1:statement1;break;
case constantExpression2:statement2:break; default:statement2;break;}
This would be always the first thing to do when you need to use the external function. Crowtail-LED
Matrix is an I2C module, so we need to import I2C library(Wire.h) first. Then we import LED Matrix’s
library “Adafruit_LEDBackpack.h” and servo’s library “Servo.h”.
Import library: #include <Wire.h> #include "Adafruit_LEDBackpack.h" #include
<Servo.h>
Create instances of LED Matrix and servo, so we can use the instance object to control the LED
Matrix and servo.
Create instance: Adafruit_8x8matrix matrix; Servo myservo;
We use the matrix.setTextSize () function to set the text size displayed on the LED matrix. 1 is a good
choice for 8x8 LED matrix display. You can try changing 1 to 2 and see what the LED matrix will look
like.
,.
Text size: matrix.setTextSize(1);
Using matrix.setTextWrap() function we can set whether the text display on LED Matrix is wrapped or
scroll. If the parameters in the brackets are true, the display text effect is wrapped, if it is false, the
display text effect is scroll.
Wrap of scroll: matrix.setTextWrap(false);
Code usage
Содержание Crowtail
Страница 48: ......