#include <LiquidCrystal.h>
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// pin definition for the Uno
#define cs 10
#define dc 8
#define rst 9
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
unsigned long lastUpdate;
TFT TFTscreen = TFT(cs, dc, rst);
byte fullBlock[] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
byte halfBlock[] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000
};
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
lcd.createChar(0, fullBlock);
lcd.createChar(1, halfBlock);
TFTscreen.begin();
}
void displayBarAndValue(int potValue, int t_barra) {
// Clear the LCD
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(potValue);
lcd.setCursor(0, 0);
// Display the bar graph
for (int i = 0; i < t_barra-1 ; i++) {
lcd.write(byte(0));
}
lcd.setCursor(t_barra-1, 0);
if ( t_barra %2 == 0 ){
lcd.write( byte(0));
}
else{
lcd.write( byte(1));
}
}
int altura = TFTscreen.height();
int x_inicial = 50;
int valor_pot; // Reading from potentiometer
// Map to 16 columns
long last_millis;
void loop() {
valor_pot= 0 ;
valor_pot = analogRead(A0);
int t_barra = map(valor_pot, 0, 1023, 0, 16);
lcd.setCursor(0, 2);
lcd.print(valor_pot);
TFTscreen.background(192, 192, 192);
TFTscreen.stroke(255, 255, 255);
int new_y = map ( valor_pot ,0, 1023, 0, altura );
TFTscreen.setTextSize(5);
TFTscreen.line(x_inicial, 0 , x_inicial, new_y);
displayBarAndValue(valor_pot, t_barra);
while ( valor_pot == 1023 ){
TFTscreen.background(0, 0, 0);
valor_pot = analogRead(A0);
}
while ( millis() - last_millis< 100){
continue;
}
last_millis = millis();
}