- Katılım
- 26 Eyl 2017
- Mesajlar
- 11
- Puanları
- 1
- Yaş
- 29
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #include <LiquidCrystal.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); int in1 = 9; int in2 = 5; int ena = 6; const int dataIN = 2; unsigned long prevmillis; unsigned long duration; unsigned long lcdrefresh; int rpm; boolean currentstate; boolean prevstate; void setup() { Serial.begin(9600); lcd.begin(); lcd.backlight(); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(ena, OUTPUT); digitalWrite(in1, HIGH); digitalWrite(in2, LOW); pinMode(dataIN,INPUT); prevmillis = 0; prevstate = LOW; } void loop() { currentstate = digitalRead(dataIN); if( prevstate != currentstate) { if( currentstate == HIGH ) { duration = ( micros() - prevmillis ); rpm = (6000000/duration); prevmillis = micros(); } } prevstate = currentstate; if( ( millis()-lcdrefresh ) >= 100 ) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Motor Hizi"); lcd.setCursor(0,1); lcd.print("RPM = "); lcd.print(rpm); lcdrefresh = millis(); } int pot_deger = analogRead(1); int motor_hizi = map(pot_deger, 0, 1023, 255, 0); analogWrite(ena, motor_hizi); } |