BASIC4MCU | 질문게시판 | 아구이노 코드를 atmega 128 코드로 변환 하고 싶습니다 ㅠㅠ
페이지 정보
작성자 기로롱 작성일2023-06-05 14:15 조회1,390회 댓글1건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=22806
본문
int encoder_pin = 2; // pulse output from the module
int pulses;
unsigned long timeold;
int pinState = 0;
int lastpinState = 0;
int laju;
int turn;
void setup()
{
Serial.begin(9600);
pinMode(encoder_pin, INPUT);
attachInterrupt(0, counter, FALLING);
pulses = 0;
timeold = 0;
}
void loop()
{
if (millis() – timeold >= 500) {
detachInterrupt(0);
laju=(pulses)*(6.28/10000)*1000*60; //number pulses in 500ms with 20 hole disk
turn=(pulses)/10;
Serial.print(pulses);
Serial.print(” pulses/500ms “);
Serial.print(laju);
Serial.print(” rpm”);
Serial.print(” “);
Serial.print(turn);
Serial.println(” turn/second”);
timeold = millis();
pulses = 0;
attachInterrupt(0, counter, FALLING);
}
}
void counter()
{
pinState = digitalRead(encoder_pin);
if (pinState != lastpinState) {
if (pinState == HIGH) {
pulses++;
}
lastpinState = pinState;
}
}
댓글 1
조회수 1,390master님의 댓글
master 작성일
https://cafe.naver.com/circuitsmanual/147325
https://cafe.naver.com/circuitsmanual/40823
https://cafe.naver.com/circuitsmanual/19483
초보자라면 공부해야 할 것이 꽤 되겠습니다.