
* 본 이미지는 참고용입니다.제품의 정확한 사양은 데이터시트를 참고 바랍니다.

상품상세정보
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #define FLOWSENSORPIN 2 // 핀 번호 설정 volatile uint16_t pulses = 0; // 데이터 유형 설정 volatile uint8_t lastflowpinstate; volatile uint32_t lastflowratetimer = 0; volatile float flowrate; SIGNAL(TIMER0_COMPA_vect) { uint8_t x = digitalRead(FLOWSENSORPIN); // 유량측정센서 값을 디지털로 읽음 if (x == lastflowpinstate) { lastflowratetimer++; return; } if (x == HIGH) { // x값이 들어오면 pulse값을 1 증가시킴 pulses++; } lastflowpinstate = x; flowrate = 1000.0; flowrate /= lastflowratetimer; lastflowratetimer = 0; } void useInterrupt(boolean v) { // bool값에 따른 출력 설정 if (v) { OCR0A = 0xAF; TIMSK0 |= _BV(OCIE0A); } else { TIMSK0 &= ~_BV(OCIE0A); } } void setup() { // 센서 통신속도 설정 및 입출력 설정 Serial.begin(9600); pinMode(FLOWSENSORPIN, INPUT); digitalWrite(FLOWSENSORPIN, HIGH); lastflowpinstate = digitalRead(FLOWSENSORPIN); useInterrupt(true); } void loop() // 시리얼 모니터에 출력 { Serial.print("Freq: "); Serial.print(flowrate); Serial.print(" "); Serial.print("Pulses: "); Serial.print(pulses, DEC); Serial.print(" "); float liters = pulses; liters /= 7.5; liters /= 60.0; Serial.print(liters); Serial.println(" Liters"); delay(1000); } | cs |
등록된 사용후기
사용후기가 없습니다.
등록된 상품문의
상품문의가 없습니다.












