Académique Documents
Professionnel Documents
Culture Documents
5''
/*
Revisions
rev date author description
1 12-24-2015 kasprzak initial creation
*/
/*
Funci�n para dibujar un sistema de coordenadas cartesianas y trazar los datos que
desee
Solamente se debe pasar 'x' y 'y' y se dibujar� el gr�fico
LISTA DE ARGUMENTOS
&d nombre del display utilizado
x = punto x de datos(ES COMO EN MATLAB EL VECTOR X o N, solo q no es vector sino
que es un dato double)
y = punto y de datos(ES COMO EN MATLAB EL VECTOR DE LA FUNCION
Y.........''.......)
gx = ubicacion del grafico en x (abajo a la izquierda)
gy = ubicacion del grafico en x (abajo a la izquierda)
w = width of graph(ANCHO DEL GRAFICO)
h = height of graph(ALTURA DEL GRAFICO)
xlo = lower bound of x axis(l�mite inferior del eje x)
xhi = upper bound of x asis(l�mite superior del eje x)
xinc = division of x axis (distance not count)
ylo = lower bound of y axis
yhi = upper bound of y asis
yinc = division of y axis (distance not count)
title = title of graph
xlabel = x asis label
ylabel = y asis label
&redraw = flag to redraw graph on first call only(bandera para volver a dibujar
el gr�fico en la primera llamada solamente)
color = color de trazadao de la funcion Trace
*/
// Graph(tft, x, y, 1, 60, 290, 390, 260, 0, 6.5, 1, -1, 1, .25, "", "", "",
display1, YELLOW);
void Graph(TFT_HX8357_Due &tft, double x, double y, byte dp,
double gx, double gy, double w, double h,
double xlo, double xhi, double xinc,
double ylo, double yhi, double yinc,
char *title, char *xlabel, char *ylabel,//cuando le
pongo * es porque era de otro tipo y le estoy pasando a otro tipo char en este caso
boolean &redraw, unsigned int color) {
redraw = false;
// initialize old x and old y in order to draw the first point of the graph
// pero guarda el valor transformado
// note que mi funci�n de transformaci�n es la misma que la funci�n map,
excepto que map usa long y necesitamos double
//ox = (x - xlo) * ( w) / (xhi - xlo) + gx;
//oy = (y - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
// draw y scale
for ( i = ylo; i <= yhi; i += yinc) {//inicia desde el limite inferior de y
hasta el limite superior de y en pasos de la division del eje y
// compute the transform
temp = (i - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
if (i == 0) {
tft.drawLine(gx, temp, gx + w, temp, acolor);
tft.setTextColor(acolor, bcolor);
tft.drawString(xlabel, (int)(gx + w) , (int)temp, 2);
}
else {
tft.drawLine(gx, temp, gx + w, temp, gcolor);
}
// draw the axis labels
tft.setTextColor(tcolor, bcolor);
// precision is default Arduino--this could really use some format control
tft.drawFloat(i, dp, gx - 4, temp, 1);
}
// draw x scale
for (i = xlo; i <= xhi; i += xinc) {
//Trace(tft, n, ln, 1, 60, 290, 390, 260, 0, 6.5, 1, -1, 1, .25, "Sin(x) + Cos(x) +
Tan(x)", " x", "fn(x)", update1, CYAN);
void Trace(TFT_HX8357_Due &tft, double x, double y, byte dp,
double gx, double gy,
double w, double h,
double xlo, double xhi, double xinc,
double ylo, double yhi, double yinc,
char *title, char *xlabel, char *ylabel,
boolean &update1, unsigned int color)
{
double ydiv, xdiv;
double i;
double temp;
int rot, newrot;
if (update1) {
update1 = false;
tft.setTextDatum(MR_DATUM);
// draw y scale
for ( i = ylo; i <= yhi; i += yinc) {
// compute the transform
temp = (i - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
if (i == 0) {
tft.setTextColor(acolor, bcolor);
tft.drawString(xlabel, (int)(gx + w) , (int)temp, 2);
}
// draw the axis labels
tft.setTextColor(tcolor, bcolor);
// precision is default Arduino--this could really use some format control
tft.drawFloat(i, dp, gx - 4, temp, 1);
}
// draw x scale
for (i = xlo; i <= xhi; i += xinc) {
/*
*/
void setup() {
double x, y, duracion,dax;
int F, Fs;
float Td;
double T, aux;
int Tm,i ;
tft.begin();
tft.fillScreen(BLACK);
tft.setRotation(1);
update1 = true;
F=1;//frecuencia de la se�al
Fs=200*F;//numero de muestras (200) por cada periodo
Tm=5;//periodos muestrales en el lcd
duracion = Tm*(1/((float)F));//duracion que sea 3 periodos de mi se�al
dax=(1/((float)F));//division para el eje x... ojo que este maximo imprime 0.1
no 0.15 debo tener en cuenta esto asi que hay que cambiar
Td=1/((float)Fs);
T=1/((float)F);
Graph(tft, x, y, 1, 60, 290, 390, 260, 0, duracion, dax, -1, 1, .1, "", "", "",
display1, YELLOW);//Primero se grafica el sistema de coordenadas
delay(1000);//espera 1 segundo
update1 = true;