motor.h motor.cpp main.cpp

Dependencies:   mbed Motor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "motor.h"
00003 
00004 Motor motor1(D5, D4);
00005 DigitalOut motor_mode(D13);
00006 InterruptIn iin(D12);
00007 Ticker timer1;
00008 Ticker timer2;
00009 
00010 void PGsensor()
00011 {
00012     motor1.count();
00013 }
00014 
00015 void rpm_of_motor()
00016 {
00017     motor1.calc_rpm();
00018 }
00019 
00020 void control_motor()
00021 {
00022     motor1.drive();
00023 }
00024 
00025 int main()
00026 {
00027     motor1.Set_target(3000);
00028     motor1.Set_phase(1);
00029     
00030     iin.rise(&PGsensor);
00031     iin.fall(&PGsensor);
00032 
00033     timer1.attach(&rpm_of_motor, motor1.MEASUREMENT_INTERVAL);
00034     timer2.attach(&control_motor, motor1.MEASUREMENT_INTERVAL);
00035 }