Question: hey just need some one to look at this code its supposed to have am and pm in the clock section but cant get it

hey just need some one to look at this code its supposed to have am and pm in the clock section but cant get it to work and i want it to read the numbers with a 0 before them while its in single digits
#include
LiquidCrystal lcd(12,11,5,4,3,2);
int ampm;
int hours;
int minutes;
int seconds;
int disp_hours;
int rawval;
float scaled_temp;
int pm;
int am;
void setup()
{
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);
lcd.begin(16,2);
Serial.begin(9600);
pm = pm;
hours =1;
minutes =0;
seconds =0;
disp_hours =1;
}
void loop(){
int reading = analogRead(A2); // read value returned by temperature sensor at analog input A0
float voltage = reading *5.0; // converting that reading to voltage
voltage /=1023.0;
float temperatureC =(voltage -0.5)*100 ; //converting from 10 mv per degree wit 500 mV offset to degrees ((voltage -500mV) times 100)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time:");
lcd.setCursor(8,0);
lcd.print(":");
lcd.setCursor(11,0);
lcd.print(":");
lcd.setCursor(6,0);
lcd.print(disp_hours);
lcd.setCursor(9,0);
lcd.print(minutes);
lcd.setCursor(12,0);
lcd.print(seconds);
if (hours >=12)
lcd.setCursor(0,14);
lcd.print("AM");
}
lcd.setCursor(0,1);
lcd.print("Temp: ");
lcd.print(temperatureC);
lcd.print("C");
delay(500);
bool cal_hrs;
bool cal_min;
int disphours;
int raw_analogue;
cal_hrs = digitalRead(A4);
cal_min = digitalRead(A5);
if(cal_hrs)
{
raw_analogue = analogRead(A0);
hours = scale_analogue(raw_analogue, 5.0/23.0,-5.0/23.0);
seconds =0;
delay(100);
}
else if(cal_min)
{
raw_analogue = analogRead(A1);
minutes = scale_analogue(raw_analogue, 5.0/59.0,0);
seconds =0;
delay(100);
}
else
{
seconds +=1;
if(seconds >=60)
{
minutes +=1;
seconds =0;
}
if(minutes >=60)
{
hours +=1;
minutes =0;
}
if(hours >24)
{
hours =1;
}
delay(1);
}
disp_hours = hours;
ampm =0;
if(hours >12)
{
disp_hours =hours -12 ;
ampm =1;
}
}
float scale_analogue(int raw_value, float gradient, float intercept)
{
float voltage;
voltage =((raw_value *5.0)/1023.0);
return (voltage-intercept)/gradient;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!