#include "TimerOne.h" //Include Timer1 library for using Timer1 functions
#include <LiquidCrystal.h> //Include LCD library for using LCD display functions
const int rs = 12, en = 13, d4 = 8, d5 = 9, d6 = 10, d7 = 11; //Define the LCD pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
volatile unsigned int counter=0;
volatile unsigned int rotation=0;
float rotationinm=0;
unsigned int speed=0;
void count() // ISR for counts from the speed sensor
{
counter++; //increase the counter value by one
rotation++; //Increase the rotation value by one
delay(10);
}
void timerIsr()
{
detachInterrupt(digitalPinToInterrupt(2)); //Stops the interrupt pin 2
Timer1.detachInterrupt(); //Stops the timer1 interrupt
lcd.clear();
float speed = (counter / 20.0)* 60.0; //Calculate speed in minute (20-No of slots in Encoder Wheel)
float rotations = 230*( rotation / 20); //Calculate distance in cm (230-Circumference of the wheel assumed 20- No of slots)
rotationinm = rotations/100;
lcd.setCursor(0,0);
lcd.print("Dist(m):");
lcd.print(rotationinm); //Display rotationinm at LCD
lcd.setCursor(0,1);
lcd.print("Speed(RPM):");
lcd.print(speed); //Dsiplay speed in RPM
counter=0; //Reset counter to 0
int analogip = analogRead(A0); // Analog read from pin A0
int motorspeed = map(analogip,0,1023,0,255); //convert digital vales 0-1023 to 0-255
analogWrite(5,motorspeed); //Sets PWM value at pin 5
Timer1.attachInterrupt( timerIsr ); //Starts timer1 again
attachInterrupt(digitalPinToInterrupt(2), count, RISING); //Attaches interrupt at pin2 again
}
void generatefare() //ISR to generate the fareamount
{
detachInterrupt(digitalPinToInterrupt(2)); //Disables the Interrupt pin at 2
Timer1.detachInterrupt(); //Disables the Timer1 interrupt
float Taka = rotationinm*5; //Muliply 5 with distance travelled (tk 5 per meter )
lcd.clear(); //Clears LCD
lcd.setCursor(0,0);
lcd.print("FARE BDT: ");
lcd.print(Taka); //Display fare amount
lcd.setCursor(0,1);
lcd.print("TK 5 per metre");
}
void setup()
{
pinMode(A0,INPUT); //Sets pin A0 as INPUT
pinMode(5,OUTPUT); //Sets pin 5 as OUTPUT
lcd.begin(16,2); //Sets LCD as 16x2 type
lcd.setCursor(0,0); //The following code displays welcome messages
lcd.print(" EAST WEST ");
lcd.setCursor(0,1);
lcd.print(" UNIVERSITY");
delay(3000);
lcd.clear();
lcd.setCursor(0,0); //The following code displays welcome messages
lcd.print("Course:EEE401");
lcd.setCursor(0,1);
lcd.print("Section: 01");
delay(3000);
lcd.clear();
lcd.setCursor(0,0); //The following code displays welcome messages
lcd.print("Project By");
lcd.setCursor(0,1);
lcd.print("Group 01");
delay(3000);
lcd.clear();
lcd.setCursor(0,0); //The following code displays welcome messages
lcd.print("Group Members:");
delay(3000);
lcd.clear();
lcd.setCursor(0,0); //The following code displays welcome messages
lcd.print("Taisir Rahi");
lcd.setCursor(0,1);
lcd.print("ID:2016-1-80-009");
delay(3000);
lcd.clear();
lcd.setCursor(0,0); //The following code displays welcome messages
lcd.print("Anisur Rahman");
lcd.setCursor(0,1);
lcd.print("ID:2016-3-80-002");
delay(3000);
lcd.clear();
lcd.setCursor(0,0); //The following code displays welcome messages
lcd.print("Sajoy Hasan");
lcd.setCursor(0,1);
lcd.print("ID:2017-2-80-011");
delay(3000);
lcd.clear();
lcd.setCursor(0,0); //The following code displays welcome messages
lcd.print("Instructor:");
lcd.setCursor(0,1);
lcd.print("FAKIR MASHUQUE");
delay(4000);
lcd.clear();
lcd.setCursor(0,0); //The following code displays welcome messages
lcd.print("BANGLADESH");
lcd.setCursor(0,1);
lcd.print("WELCOME TO TAXI");
delay(3000);
lcd.clear();
lcd.print("START RIDING:");
delay(1000);
lcd.clear();
Timer1.initialize(1000000); //Initilize timer1 for 1 second
Timer1.attachInterrupt( timerIsr ); //ISR routine to be called for every one second
attachInterrupt(digitalPinToInterrupt(2), count, RISING); // Pin 2 as Interrupt pin with count ISR is called when LOW to RIGH happens.
attachInterrupt(digitalPinToInterrupt(3), generatefare, HIGH); //Pin 3 as Interrupt pin with generatefare ISR is called when HIGH is detected.
}
void loop()
{
}
Comments
Please log in or sign up to comment.