10
The 5V, 83rpm Micro DC Geared Motor with Back Shaft is ideal for DIY enthusiasts. This motor is
inexpensive, small, easy to install, and ideally suited for use in a mobile robot car. Its no-load speed
is 50rpm under 3V voltage operation and 83rpm under 5V voltage operation.
Lesson 4 – Motor control
Introduction
Code usage
'const' is the abbreviation of constants. If you use this to define variables, the variables are marked
as “read-only”, that is, they cannot be changed during the program. Constants are great for declaring
pin number variables that will not change throughout the program. Here we declare the “taketime”
constant and it assigned to 5000, which mean we will get the count of speed every 5 seconds.
Constant: const int taketime = 5000;
The prototype of the interrupt function is: attachInterrupt(interrupt
,
function
,
mode). “Interrupt”:
Interrupt source (In Arduino, the selectable value of the interrupt source is 0 or 1, generally
corresponding to pins 2 and 3 respectively). “function”: the name of the function that needs to be
interrupted. “mode”: LOW (low level trigger), CHANGE (trigger when change), RISING (low-level to
high-level trigger), FALLING (high-level to low-level trigger). We use a Hall sensor as the interrupt
source connected to the D3 port. When the interrupt occurs (the S level of the magnet is close to the
Hall sensor), this means that the high level signal of the Hall sensor will become a low level signal,
and then we run the code in the count function.
Interrupt function: attachInterrupt(digitalPinToInterrupt(interruptPin), count, FALLING);
Each type of integer is divided into two types: unsigned and signed (float and double are always
signed). In data types other than char, integers declared by default Type variables are all signed
types; char is always unsigned by default. The long keyword represents a long integer type, which is
a basic data type in a programming language. It is an abbreviation of long int. The default is a signed
long integer type.
Unsigned long integer: unsigned long time;
This function returns the number of milliseconds when the Arduino board starts running the current
program. This number overflows after about 50 days and returns to zero. By using this function, we
can precisely control the program to calculate the count of speed every 5 seconds and print it out in
the serial monitor.
Millis() function: time = millis();
Содержание Crowtail Deluxe Kit
Страница 47: ......