#include "TimerOne.h"
unsigned int counter=0;
int b1a = 12; //6; // L9110 B-1A
int b1b = 9; // L9110 B-1B
void docount() // counts from the speed sensor
{
counter++; // increase +1 the counter value
}
void timerIsr()
{
Timer1.detachInterrupt(); //stop the timer
Serial.print("Motor Speed: ");
int rotation = (counter / 20); // divide by number of holes in Disc
Serial.print(rotation,DEC);
Serial.println(" Rotation per seconds");
counter=0; // reset counter to zero
Timer1.attachInterrupt( timerIsr ); //enable the timer
}
void setup()
{
Serial.begin(9600);
pinMode(b1a, OUTPUT);
pinMode(b1b, OUTPUT);
Timer1.initialize(1000000); // set timer for 1sec
//Serial.print(digitalPinToInterrupt(2));
//Serial.print(digitalPinToInterrupt(3));
attachInterrupt(0, docount, RISING); // increase counter when speed sensor pin goes High
Timer1.attachInterrupt( timerIsr ); // enable the timer
}
void loop()
{
int potvalue = analogRead(1); // Potentiometer connected to Pin A1
potvalue=0;
int motorspeed = map(potvalue, 0, 680, 255, 0);
analogWrite(b1a, motorspeed); // set speed of motor (0-255)
digitalWrite(b1b, 1); // set rotation of motor to Clockwise
}
'프로세싱+아두이노+안드로이드' 카테고리의 다른 글
아두이노-푸리에 변환 (FFT)과 활용 (0) | 2022.05.14 |
---|---|
Build a Robot Car with Speed Sensors (0) | 2022.05.14 |
아두이노 인터럽트의 이해 (interrupt) (0) | 2022.05.14 |
무언가 반복해서 지나가는 속도를 측정할때는 IR(적외선) 기반 Tachometer를 사용하세요 (0) | 2022.05.13 |
아두이노 차량에 스피드 센서 사용 방법 (0) | 2022.05.13 |
댓글