![]() ![]() setSpeed(speed) function controls the motor’s speed.In the setup and loop sections of the code, we simply call the two functions listed below to control the speed and direction of a motor. The following code snippet, for example, creates two AFmotor objects. If you want to connect multiple motors to the shield, make a separate object for each motor. Write 1 for port M1, 2 for port M2, and so on. Here, you must specify the motor port number to which the motor is connected. The second line AF_DCMotor motor(motorPort#) creates a library object. The sketch begins by including the AFMotor.h library. Decelerate from maximum speed to zero for (i= 255 i!= 0 i-) Accelerate from zero to maximum speed for (i= 0 i< 255 i++) To install the library, navigate to Sketch > Include Library > Manage Libraries… Wait for the Library Manager to download the libraries index and update the list of installed libraries. This will let us control DC, stepper, and servo motors with simple commands. To communicate with the shield, we must first install the AFMotor.h library. Please note that the shield does not use the D2 or D13 pins. D10 is connected to Servo 1, while D9 is connected to Servo 2. Arduino to Shield Pin Connectionsįor DC and stepper motor control, the shield makes use of pins D3, D4, D5, D6, D7, D8, D11, and D12.ĭ9 and D10 are used to control the servo motors. You can populate these with headers, making them useful for connecting various sensors. Six analog pins (A0 to A5), as well as 5V and ground connections, are provided in the bottom right corner. It has been brought to the top for easy access. The RESET button is nothing but Arduino’s reset button. The motors will not run if it is not lit. The on-board LED indicates that the motor power supply is working properly. The shield includes a pulldown resistor array to keep motors off during power-up. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |