回転数計のプログラムです。
Dependencies: mbed
main.cpp
- Committer:
- YusukeWakuta
- Date:
- 2017-01-07
- Revision:
- 1:3778bb7e3cf9
- Parent:
- 0:81114af7e3d0
File content as of revision 1:3778bb7e3cf9:
#include "mbed.h" #define SLIT_NUM 70 #define COUNT_NUM 10 Timer timer; PwmOut pwm(p21); InterruptIn Photo_int(p30); int counter = 0; int Cadence = 0; int beforetime = 0; int temp_time = 0; double calcPulse(int deg) { return (0.00093+(deg/180.0)*(0.00235-0.00077)); } void servo(int d) { if(d < 70) pwm.pulsewidth_us(0); if(d > 110) pwm.pulsewidth_us(180); else pwm.pulsewidth_us((d - 70) * (180 / 40)); } void Photo() { counter++; } int main() { Photo_int.fall(Photo); timer.start(); while(1) { if(counter >= COUNT_NUM) { temp_time = timer.read_ms(); Cadence = (60 / ((SLIT_NUM / COUNT_NUM) * (temp_time) - beforetime)) * COUNT_NUM; beforetime = temp_time; counter = 0; } servo(Cadence); } }