Part 1:
/*
The circuit:
* 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
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
* Pot to Analog 0
* enable pin 8
* motor 1 pin 9
* motor 2 pin 10
*/
#include <LiquidCrystal.h> // include the library code:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
int sensorPin = A1; // select the input pin for the potentiometer for time
int sensorValue = 0; // variable to store the value coming from the sensor
const int motor1Pin = 9; // H-bridge leg 1 (pin 9, 1A)
const int motor2Pin = 10; // H-bridge leg 2 (pin 10, 2A)
const int enablePin =8; // H-bridge enable pin 8
const int PotPin = A0; // input pin for the potentiometer for speed/direction
int x = 10;
int zero_speed;
int Reverse;
int Forward;
int sensorValue2 = 1; // variable to store the value coming from the sensor
int value = analogRead(PotPin); // read value from pot at sensorPin Rotation
int speed = abs(value - 512)/2 ; // 0..1023 -> -512.0..+512 -> 512..0..512 -> 256..0..256
int direction = value < 512; // or "value > 512" to reverse the action of the pot
char flag;
int countP = 0;
int countPA = 0;
int countPB = 0;
int countPC = 0;
int countPD = 0;
int count1 = 0;
int time_1;
int speed1;
int drive1;
int loop_count;
//*************************************************************************************
void enter_point_A() // Subroutime "enter_point_a"
{
lcd.clear(); // Clear Screen
lcd.setCursor(1, 0); // set the cursor to column 0, line 0
lcd.print("Enter Data for"); // Print "Enter Data for"
lcd.setCursor(4, 1); // set the cursor to column 4, line 1
lcd.print("Point A"); // Print "Point A"
delay(3000); // Delay
lcd.clear(); // Clear Screen
}
//*************************************************************************************
void Pot_SpeedA()
{
lcd.setCursor(0, 1); // set the cursor to column 0, line 1
lcd.print("Rotation:"); // Print "Rotation"
while (digitalRead(1) == LOW) // if button is not pressed
{
digitalWrite (enablePin, HIGH);
int retval = analogRead(value);
if (retval < 510)
{
Reverse = map(retval, 0, 510, 255, 0);
analogWrite (motor1Pin, Reverse);
count_pulse_neg_1();
}
else if(retval > 518)
{
Forward = map(retval, 518, 1023, 0, 255);
analogWrite (motor2Pin, Forward);
count_pulse_pos_1();
}
else
{
analogWrite (motor1Pin, 0);
analogWrite (motor2Pin, 0);
lcd.setCursor(10,1);
lcd.print(count1);
}
if (digitalRead(1) == HIGH) // if button is pressed
{ // then go to sub routine
lcd.clear(); // Clear Screen
}
}
}
//*****************************************************************************************
void Pot_TimeA()
{
while (digitalRead(1) == LOW) // if button is not pressed
{
lcd.setCursor(0, 1); // set the cursor to column 0, line 0
lcd.print("Time:"); // Print "Time"
lcd.setCursor(8, 1); // set the cursor to column 8, line 0
lcd.print("."); // Print ":"
lcd.setCursor(12, 1); // set the cursor to column 12, line 0
lcd.print("Min"); // Print "Min"
int val = analogRead(sensorPin); // read value from pot at sensorPin time
time_1 = map(val, 0, 1023, 0, 600); // map function
lcd.setCursor(6,1); // set the cursor to column 0, line 1
lcd.print(time_1/60); // Print "val/100"
lcd.setCursor(8, 1); // set the cursor to column 2, line 1
lcd.print(":"); // Print ":"
lcd.setCursor(9,1); // set the cursor to column 3, line 1
lcd.print(time_1/10); // Print "val/10"
if (digitalRead(1) == HIGH) // if button is pressed
{ // then go to sub routine
lcd.clear(); // Clear Screen
}
}
}
//*****************************************************************************************
void count_pulse_pos_1()
{
if((digitalRead(13) == HIGH) && (flag == 0))
{
count1 ++ ;
flag = 1;
digitalWrite(7, HIGH);
for (loop_count =0; loop_count < 1500; loop_count ++)
{
}
}
if((digitalRead(13) == LOW) && flag == 1)
{
flag = 0;
digitalWrite(7, LOW);
for (loop_count =0; loop_count < 1500; loop_count ++)
{
}
}
}
//***********************************************************************
void count_pulse_neg_1()
{
if((digitalRead(13) == HIGH) && (flag == 0))
{
count1 --;
flag = 1;
digitalWrite(7, HIGH);
for (loop_count =0; loop_count < 1500; loop_count ++)
{
}
}
if((digitalRead(13) == LOW) && flag == 1)
{
flag = 0;
digitalWrite(7, LOW);
for (loop_count =0; loop_count < 1500; loop_count ++)
{
}
}
}