/*
Show the voltage across potentiometer using 4 digit 7SD.
*/
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
Serial.begin(9600);
analogReference(INTERNAL);
}
void loop() {
int x = analogRead(A0);
float T = 100*(1.1 / 1023.0) * x;
Serial.println(T);
lcd.setCursor(6, 0);
lcd.print(T);
lcd.write(0xdf);
lcd.print("C");
}
// #define vREF 5 // 1.1 if INTERNAL
// byte lupTable[] =
// {
// 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07,
// 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71
// };
// void setup() {
// DDRD = 0b11000000;
// DDRB = 0b00111111;
// DDRC = 0b001111;
// Serial.begin(9600);
// analogReference(DEFAULT);
// // INTERNAL in case of LM35
// }
// void loop() {
// float myVoltage = analogRead(A5)*(vREF/1023.0);
// // Compute temperature while using LM35.
// // float myTemperature = 100*myVoltage; then use myTemperature instead of myVoltage for 7SDs.
// Serial.println(myVoltage,3);
// unsigned long presentMillis = millis();
// while(millis()-presentMillis<1000)
// {
// int convertedFor7SD = myVoltage*100;
// for(int i = 0; i<=3; i++)
// {
// byte digit = convertedFor7SD%10;
// byte y = lupTable[digit];
// if (i==2)
// y = y | 0b10000000; // to turn on decimal point
// PORTB = y;
// digitalWrite(6,bitRead(y,6));
// digitalWrite(7,bitRead(y,7));
// PORTC = 0b001111; // PORTC = DDRC; this command is also correct in this case.
// bitClear(PORTC,i);
// Serial.println(y,HEX);
// /* Use delay(10) for hardware*/
// delay(1000); // delay should be around 10-20 ms. But this simulator can't simulate that fast.
// convertedFor7SD = convertedFor7SD/10;
// }
// }
// }