BASIC4MCU | 질문게시판 | 답변 : 아두이노 우노 수위센서 응용
페이지 정보
작성자 master 작성일2018-12-08 16:29 조회6,846회 댓글1건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=6552
본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2018-12-08 오후 4:35:10// by Ok-Hyun Park//#include <Wire.h>#include <LiquidCrystal_I2C.h>LiquidCrystal_I2C lcd(0x27,16,2);//const int waterLevelPin1=A0;const int waterLevelPin2=A1;//const int buzPin=5;const int R_LED=6,G_LED=9,B_LED=10;//#define NOTE_C4 262#define NOTE_D4 294#define NOTE_E4 330#define NOTE_F4 349#define NOTE_G4 392#define NOTE_A4 440#define NOTE_B4 494#define NOTE_C5 523//const int waterFullAdcValue=600;//int Level=0;//void color(int r,int g,int b){analogWrite(R_LED,r);analogWrite(G_LED,g);analogWrite(B_LED,b);}//void setup(){lcd.init(); lcd.backlight();lcd.setCursor(0,0); lcd.print("ex 6.4");lcd.setCursor(0,1); lcd.print("Water Level");delay(3000);}//void loop(){int adcValue1=analogRead(waterLevelPin1);int adcValue2=analogRead(waterLevelPin2);int waterLevel1=map(adcValue1,0,waterFullAdcValue,0,100);int waterLevel2=map(adcValue2,0,waterFullAdcValue,0,100);lcd.clear();lcd.setCursor(0,0); lcd.print("ADC : "); lcd.print(adcValue1); lcd.print(" ");lcd.setCursor(0,1); lcd.print("Level: "); lcd.print(waterLevel1); lcd.print("%");//if(waterLevel2<5){if(waterLevel1<5){if(Level!=0){ Level=0; color(0,0,0);noTone(buzPin); lcd.setCursor(15,0); lcd.print(" ");}}else if(waterLevel1<25){if(Level!=1){ Level=1; color(0,0,0);noTone(buzPin); tone(buzPin,NOTE_C4); lcd.setCursor(15,0); lcd.print("A");}}else if(waterLevel1<50){if(Level!=1){ Level=1; color(0,255,0);noTone(buzPin); tone(buzPin,NOTE_D4); lcd.setCursor(15,0); lcd.print("B");}}else if(waterLevel1<75){if(Level!=1){ Level=1; color(0,255,255);noTone(buzPin); tone(buzPin,NOTE_E4); lcd.setCursor(15,0); lcd.print("C");}}else{if(Level!=1){ Level=1; color(255,255,0);noTone(buzPin); tone(buzPin,NOTE_G4); lcd.setCursor(15,0); lcd.print("D");}}}else{if(waterLevel2<25){if(Level!=1){ Level=1; color(0,0,255);noTone(buzPin); tone(buzPin,NOTE_G4); lcd.setCursor(15,0); lcd.print("E");}}else if(waterLevel2<50){if(Level!=1){ Level=1; color(0,255,255);noTone(buzPin); tone(buzPin,NOTE_A4); lcd.setCursor(15,0); lcd.print("F");}}else if(waterLevel2<75){if(Level!=1){ Level=1; color(255,0,255);noTone(buzPin); tone(buzPin,NOTE_B4); lcd.setCursor(15,0); lcd.print("G");}}else{if(Level!=1){ Level=1; color(255,255,255);noTone(buzPin); tone(buzPin,NOTE_C5); lcd.setCursor(15,0); lcd.print("H");}}}}
댓글 1
조회수 6,846우노새내기님의 댓글
우노새내기 작성일와...마스터님 덕분에 드디어 스케치 완성하여 작동했습니다 ! 정말 감사드립니다 최고!!