Initialize the library with the numbers of the interface pins
Download 320.54 Kb.
|
include LCD library
//include LCD library #include // initialize the library with the numbers of the interface pins //as follow : //LCD RS pin to digital pin 12 //LCD Enable pin to digital pin 11 //LCD D4 pin to digital pin 5 //LCD D5 pin to digital pin 4 //LCD D6 pin to digital pin 3 //LCD D7 pin to digital pin 2 LiquidCrystal lcd(12, 11, 5, 4, 3, 2); const int temperaturePin = 1; //determined the pin for reading TMP36 sensor int D1 = 30;
//define motor control lines as pin 3,5 for the direction and 3 for the enable and PWM const int IN3 = 7; const int IN4 = 6; const int ENB = 9; void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); pinMode(D1, OUTPUT); pinMode(D2, OUTPUT); pinMode(D3, OUTPUT); pinMode(D4, OUTPUT); //ture the two digit at the left off as we mesure number with max of 2 digit so we didn't need it digitalWrite(D2, LOW); digitalWrite(D1, LOW); //set the pins for motor pinMode (ENB, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); Serial.begin(9600); } int last_read_of_time = 0; int TMP_reading = 0; void loop() { int time_from_start = millis(); if (abs(last_read_of_time - time_from_start) >= 1000) { last_read_of_time = millis(); lcd.clear(); // start with a blank screen TMP_reading = reading_temperature_from_TMP36(); } int y; y =TMP_reading; if(y>=10 && y<=20){ digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); analogWrite(ENB,0); } else if(y>20 && y<=30){ analogWrite(ENB,63); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); } else if(y>30 && y<=40){ analogWrite(ENB,128); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); } else if(y>40 && y<=50){ analogWrite(ENB,192); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); } else if(y>50){ analogWrite(ENB,255); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); } lcd.setCursor(0, 1); // set the cursor to column 0, line 1 lcd.print(TMP_reading);//write value on LCD lcd.display();//display value }
{ float voltage, degreesC; voltage = analogRead(temperaturePin) * 0.004882814; degreesC = (voltage - 0.5) * 100.0; return degreesC; } Download 320.54 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling