#include <LedControl.h>
#include <avr/pgm.h>
int temppin = 33;
float temp = 0.0;
int const REF = 3950;
int DIN = 13;
int CLK = 14;
int CS = 5;
LedControl lc = LedControl(DIN,CLK,CS,4);
void setup() {
Serial.begin(115200);
Serial.println("Hello, ESP32!");
for(int i=0;i<4;i++){
lc.shutdown(i,false);
lc.setIntensity(i,10);
lc.clearDisplay(i);
}
}
void loop() {
temp = analogRead(temppin);
float result = 1 / (log(1 / (4095. / temp - 1)) / REF + 1.0 / 298.15) - 273.15;
Serial.println(result);
String myString = String(result, 1); // Convert the float value to a string with 5 decimal places
byte one[] = {0x18,0x38,0x78,0x18,0x18,0x18,0x18,0x7e};
byte two[] = {0x7c,0x7e,0x06,0x1c,0x38,0x60,0x7e,0x7e};
byte three[] = {0x7c,0x7e,0x06,0x3c,0x3c,0x06,0x7e,0x7c};
byte four[] = {0x66,0x66,0x66,0x7e,0x3e,0x06,0x06,0x06};
byte five[] = {0x7e,0x7e,0x60,0x7c,0x7e,0x02,0x7e,0x7c};
byte six[] = {0x3e,0x7e,0x60,0x7c,0x7e,0x62,0x7e,0x3c};
byte seven[] = {0x7e,0x7e,0x06,0x06,0x06,0x06,0x06,0x06};
byte eight[] = {0x3c,0x7e,0x66,0x3c,0x3c,0x66,0x7e,0x3c};
byte nine[] = {0x3c,0x7e,0x66,0x7e,0x3e,0x06,0x7e,0x7c};
byte zero = {0x3c,0x7e,0x66,0x66,0x66,0x66,0x7e,0x3c};
byte dot[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10};
byte c[] = {0x3e,0x7e,0x60,0x60,0x60,0x60,0x7e,0x3e};
byte f[] = {0x7e,0x7e,0x60,0x7c,0x7c,0x60,0x60,0x60};
int active_display = 0;
for (int i = 0; i < myString.length(); i++) {
char c = myString.charAt(i); // Get the character at position i in the string
int digit = c - '0'; // Convert the character to an integer
// Do something with the digit...
if(active_display == 2){
for (int i = 0; i < 8; i++) {
lc.setRow(active_display, i, dot[i]);
}
active_display++;
continue;
}
if(digit == 1){
for (int i = 0; i < 8; i++) {
lc.setRow(active_display, i, one[i]);
}
active_display++;
}
else if(digit == 2){
for (int i = 0; i < 8; i++) {
lc.setRow(active_display, i, two[i]);
}
active_display++;
}
else if(digit == 3){
for (int i = 0; i < 8; i++) {
lc.setRow(active_display, i, three[i]);
}
active_display++;
}
else if(digit == 4){
for (int i = 0; i < 8; i++) {
lc.setRow(active_display, i, four[i]);
}
active_display++;
}
else if(digit == 5){
for (int i = 0; i < 8; i++) {
lc.setRow(active_display, i, five[i]);
}
active_display++;
}
else if(digit == 6){
for (int i = 0; i < 8; i++) {
lc.setRow(active_display, i, six[i]);
}
active_display++;
}
else if(digit == 7){
for (int i = 0; i < 8; i++) {
lc.setRow(active_display, i, seven[i]);
}
active_display++;
}
else if(digit == 8){
for (int i = 0; i < 8; i++) {
lc.setRow(active_display, i, eight[i]);
}
active_display++;
}
else if(digit == 9){
for (int i = 0; i < 8; i++) {
lc.setRow(active_display, i, nine[i]);
}
active_display++;
}
else if(digit == 0){
for (int i = 0; i < 8; i++) {
lc.setRow(active_display, i, nine[i]);
}
active_display++;
}
if(active_display == 3)
break;
}
delay(1000); // this speeds up the simulation
for(int i =0; i<4;i++)
lc.clearDisplay(i);
}