14. Case 11: A Simple Fan¶
14.3. Materials Required¶
14.5. Hardware Connection¶
Connect the motor to M1 and the two buttons to J1 port on Nezha-A master box.
14.6. Programming¶
14.6.1. Prepare the programming¶
Steps for preparation please refer to: Arduino 3 in 1 Breakout Board
Import the libraries and the subsidiary libraries of Nezha-A master box and then import the libraries of the two buttons:PlanetXButton-main.zip Download and import the self-defined library connections for Nezha-A master box: RJPins-main.zip
14.6.2. Sample Code:¶
// Language ArduinoC
#include <RJPins.h>
#include <NezhaA.h>
#include <PlanetXButton.h>
PlanetXButton buttonJ1(J1); //Create an instance of PlanetXButton category
NezhaA nezhaA; //Create an instance of NezhaA category
void setup() {
nezhaA.begin(); //Initiliaze the buzzer, motor, servo and light
}
void loop() {
if (buttonJ1.isPressed(C)) { //While button C is pressed
nezhaA.setMotorSpeed(M1, 100); //Set the speed of the motor connecting to M1 at 50%
}
if (buttonJ1.isPressed(D)) { //While button D is pressed
nezhaA.brakeMotor(M1);
}
}
14.6.3. Result¶
After powering on, press button C to drive the motor and press button D to stop driving.