Hi,
I have an Arduino Leonardo and a Robot LCD.
In my program I have a varible that can have the values from 1 to 12 and I need to print that value on the LCD.
Can some one help me?
Thank you,
Miguel
Hi,
I have an Arduino Leonardo and a Robot LCD.
In my program I have a varible that can have the values from 1 to 12 and I need to print that value on the LCD.
Can some one help me?
Thank you,
Miguel
What do you mean by "Robot LCD"? Is Robot a brand name?
This should help in most cases:
Hi.
It's not hard to do that, assuming your LCD is a 1602 like version.
Just print it to the screen without the " " quotes.
Like this:
lcd.print(variable);
You can find plenty of examples of this, so should have had no problem finding this without asking for it.
If you have another (graphical) display, you might need to use an other way to get this done.
In that case tell more about the display.
The "LCD Robot" is the name of the Board Model for the "Arduino TFT CD Screen" (http://arduino.cc/en/Main/GTFT)
Convert your variable into a string before printing it out.
I'm converting it this way but nothing is printing out:
"
char saida[1];
void loop()
String(VariavelHz).toCharArray(saida, 1);
TFTscreen.stroke(255,255,255);
TFTscreen.text(saida,20,60);
"
The "VariavelHz" is the varible that can have the values from 1 to 12
I've change the code to this one and it's printing but it's messing with the rest of the program.
"
char saida[3];
void loop()
String(VariavelHz).toCharArray(saida, 3);
TFTscreen.stroke(255,255,255);
TFTscreen.text(saida,20,60);
"
If I take out this psrt of the program everything else works perfectly.
Can someone help me?
Kardozy:
it's printing but it's messing with the rest of the program.
If I take out this psrt of the program everything else works perfectly.
Can someone help me?
Since we can't see your sketch from here it will be hard to help.
This is the all sketch:
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// ATRIBUIÇAO das variaveis de INPUT E OUTPUT PINS.
int outPin = 13; //VARIAVEL DO PIN DE OUTPUT.
int Direcao = 12; //OUTPUT PARA MUDANÇA DE DIREÇÃO
int Controlomais = 11; //CONTROLO DO SINAL DE FIM DE CURSO
int Controlomenos = 10; //CONTROLO DO SINAL DE 10 Hz
int Fimdecurso = 5; //INTERRUPTOR DE FIM DE CURSO ESQUERDO E DIREITO
int BUT1hz = 6; //BOTAO DE 1 HZ
int BUT10hz = 7; //BOTAO DE 10 HZ
int BUTmaisHz = 8; //BOTAO DE + 1 HZ
int BUTmenosHz = 9; //BOTAO DE - 1 HZ
// Atribuição de Pins para o LCD
#define cs 2
#define dc 0
#define rst 1
TFT TFTscreen = TFT(cs, dc, rst);
//variaveis que vão conter os valores de leitura de cada pin de INPUT
int LER_Fimdecurso;
int LER_BUT1hz;
int LER_BUT10hz;
int LER_BUTmaisHz;
int LER_BUTmenosHz;
int CICLO = 5000; // VARIAVEL DE TEMPO DE CICLO
int VariavelHz = 1; // VARIAVEL DE TEMPO DE CICLO
int VariavelHz_Anterior = 1; // VARIAVEL DE TEMPO DE CICLO
int VELOCIDADE = 500; // VARIAVEL DE TEMPO DE CICLO
int CICLO_Anterior = 500; // VARIAVEL DE TEMPO DE CICLO ANTERIOR
int TempoPULSE = 100; // VARIAVEL tempo de duração de cada impulso
long ControloDirecao = LOW;
long Fimdecurso_anterior = LOW;
long BUTmaisHz_Anterior = LOW;
long BUTmenosHz_Anterior = LOW;
char saida[3];
char saida_anterior[3];
void setup()
{
// DEFINIR A DIREÇÃO DE CADA PIN USADO, SE É INPUT OU OUTPUT
pinMode(outPin, OUTPUT);
pinMode(Direcao, OUTPUT);
pinMode(Controlomais, OUTPUT);
pinMode(Controlomenos, OUTPUT);
pinMode(Fimdecurso, INPUT);
pinMode(BUT1hz, INPUT);
pinMode(BUT10hz, INPUT);
pinMode(BUTmaisHz, INPUT);
pinMode(BUTmenosHz, INPUT);
// LCD
TFTscreen.begin();
TFTscreen.background(0, 0, 0); // clear the screen with a black background
TFTscreen.stroke(255,255,255); // set the font color to white
TFTscreen.setTextSize(2); // set the font size
TFTscreen.text("Velocidade:",10,20); // write the text to the top left corner of the screen
TFTscreen.setTextSize(5); // set the font size very large for the loop
TFTscreen.text("Hz",85,60);
}
void loop() // inicio do loop do programa
{
// LEITURA DOS ESTADOS DE CADA BUTÃO
LER_Fimdecurso = digitalRead(Fimdecurso);
LER_BUT1hz = digitalRead(BUT1hz);
LER_BUT10hz = digitalRead(BUT10hz);
LER_BUTmaisHz = digitalRead(BUTmaisHz);
LER_BUTmenosHz = digitalRead(BUTmenosHz);
VariavelHz_Anterior = VariavelHz;
CICLO_Anterior = CICLO;
if (LER_BUT1hz == HIGH) VariavelHz = 1;
if (LER_BUT10hz == HIGH) VariavelHz = 10;
if (LER_BUTmaisHz == HIGH) //SE CARRREGAR NO BOTÃO DE "MAIS HZ" ENTÃO TEMPO DE CICLO DIMINUI
{if (BUTmaisHz_Anterior == LOW){
VariavelHz = VariavelHz + 1;
if (VariavelHz > 12) VariavelHz = 12;
}
}
if (LER_BUTmenosHz == HIGH) //SE CARRREGAR NO BOTÃO DE "MENOS HZ" ENTÃO TEMPO DE CICLO AUMENTA
{if (BUTmenosHz_Anterior == LOW){
VariavelHz = VariavelHz - 1;
if (VariavelHz < 1) VariavelHz = 1;
}
}
VELOCIDADE = CICLO;
BUTmaisHz_Anterior = LER_BUTmaisHz;
BUTmenosHz_Anterior = LER_BUTmenosHz;
if (VariavelHz == 1) CICLO = 5000;
if (VariavelHz == 2) CICLO = 2500;
if (VariavelHz == 3) CICLO = 1667;
if (VariavelHz == 4) CICLO = 1250;
if (VariavelHz == 5) CICLO = 1000;
if (VariavelHz == 6) CICLO = 833;
if (VariavelHz == 7) CICLO = 714;
if (VariavelHz == 8) CICLO = 625;
if (VariavelHz == 9) CICLO = 556;
if (VariavelHz == 10) CICLO = 500;
if (VariavelHz == 11) CICLO = 455;
if (VariavelHz == 12) CICLO = 417;
//String Motor = String(VariavelHz);
String(VariavelHz).toCharArray(saida, 3);
String(VariavelHz_Anterior).toCharArray(saida_anterior, 3);
if (VariavelHz_Anterior == VariavelHz){
TFTscreen.stroke(255,255,255);
TFTscreen.text(saida,20,60);
}
else {
TFTscreen.stroke(0,0,0);
TFTscreen.text(saida_anterior,20,60);
}
// VARIAÇÃO DO TEMPO DE IMPULSO PARA QUE O DELAY NAO ULTRAPASSE OS 3500 MICROSEGUNDOS)
if (CICLO >= 3000) TempoPULSE = 2500;
else TempoPULSE = 100;
// MUDANÇA DE DIREÇÃO
if (LER_Fimdecurso == HIGH)
{
if (Fimdecurso_anterior == LOW){
CICLO = 5000;
VELOCIDADE = 5000;
if (ControloDirecao == LOW){
ControloDirecao = HIGH;
digitalWrite(Direcao, ControloDirecao);}
else{
ControloDirecao = LOW;
digitalWrite(Direcao, ControloDirecao);}
}
}
// RAMPA DE ACELERAÇÃO
if (VELOCIDADE > CICLO) CICLO = CICLO_Anterior - 15;
Fimdecurso_anterior = LER_Fimdecurso;
// CONTROLO DE ENTRADAS
digitalWrite(Controlomais, LER_BUTmaisHz);
digitalWrite(Controlomenos, LER_BUTmenosHz);
digitalWrite(outPin, HIGH);
delayMicroseconds(TempoPULSE/10); // DURAÇÃO DO IMPULSO EM CADA CICLO (TEMPO QUE O OUTPUT FICA LIGADO).
digitalWrite(outPin, LOW);
delayMicroseconds(CICLO/10 - TempoPULSE/10); // TEMPO DO CICLO (menos a duração do impulso)
}
Hi.
I bet you didn't actually have put smilies in your code, did you ?
Take some time to read this (click !) and learn how to use [code] [/code]
tags so others are able to read the code correctly.
After that, apply what you have learned to your previous post, by editing it accordingly.
In future please use code tags to post code, makes life so much easier to people that come to your rescue.
Hi.
I understand that you are using variables and comments in your own language, Portuguese, but that makes it a bit harder to get what's going on for me.
//String Motor = String(VariavelHz);
String(VariavelHz).toCharArray(saida, 3);
String(VariavelHz_Anterior).toCharArray(saida_anterior, 3);
if (VariavelHz_Anterior == VariavelHz){
TFTscreen.stroke(255,255,255);
TFTscreen.text(saida,20,60);
}
else {
TFTscreen.stroke(0,0,0);
TFTscreen.text(saida_anterior,20,60);
}
This seems to be where you are printing values to your screen.
You are printing a new value in white, and an old value in black, correct ?
You are checking to see if the old variable equals the actual variable, and in that case the new variable is printed in white.
If they aren't equal, the old variable is printed in black, is that correct ?
Wasn't your background also set to black, rendering this old variable illegible ?
Do you have an idea about how often you are writing a new value to your screen (how long does a typical iteration take) ?
So can your screen keep up with that ?
You seem to write to your screen in every iteration.
I'd look for a way to only write to the screen if something has changed.
Or in some fixed periods, like twice a second or so.
Finally, your reporting "it's messing with the rest of the program".
What do you mean by that, what are you expecting to happen, and what does (seem to) happen ?
When you say "it's printing but it's messing with the rest of the program" what exactly do you mean? I don't see anything obviously wrong with your sketch.