제조사 | OEM |
---|---|
브랜드 | 에듀이노 |
판매가 | 22,000원 |
적립금 | 220원 |
자체상품코드 | C-78 |
상품요약정보 | YF-S201 |
국내·해외배송 | 국내배송 |
배송방법 | 택배 |
수량 |
COMMENT |
(최소주문수량 1개 이상 / 최대주문수량 0개 이하)
사이즈 가이드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 |