Please some one can give a little part of code to display a waveform like a sinus on a GLCD Graphical?
I know thtat the mathematical equation for the sinus is y=sinx but when i want to translate it in c program to display the sinus on a glcd it does not work
Using PIC16F887 And T6963C Controler 128*64
Code:
void Trace_Sinus(){
char x1 = 0;
do{
T6963C_line(6, 30, x1,y1, T6963C_WHITE); // this functions trace a line 6, 30 are the left coord and x1 y1 the right coord
x1++.
y1 = sin(x1);
}
while(x1<128);
sin(x)
x in degrés 0 to 360 or radiant x* PI/180 ?
i don't know your type of LCD,but you can try this:
Code:
maybe include also a library link "math.h"
char x1,y1 = 0;
float x,y;
do
{
x= (float)x1;
y=sin(x)*30.0+32.0; // offest 32 and range +-30 around the offset
y1=(int)y;
T6963C_line(x1, 32, x1,y1, T6963C_WHITE); // this functions trace a line 6, 30 are the left coord and x1 y1 the right coord
// maybe you have an equivalent of putPixel(x1,y1) instead of using line function?
x1++;
}
while(x1<128);
sin(x)
x in degrés 0 to 360 or radiant x* PI/180 ?
i don't know your type of LCD,but you can try this:
Code:
maybe include also a library link "math.h"
char x1,y1 = 0;
float x,y;
do
{
x= (float)x1;
y=sin(x)*30.0+32.0; // offest 32 and range +-30 around the offset
y1=(int)y;
T6963C_line(x1, 32, x1,y1, T6963C_WHITE); // this functions trace a line 6, 30 are the left coord and x1 y1 the right coord
// maybe you have an equivalent of putPixel(x1,y1) instead of using line function?
x1++;
}
while(x1<128);
i ve tried your code, it work but i dont really have a sinus, can you give me the code which trace a perfect sinus, the equivalent of putpixel is T6963C_dot(x0, y0, T6963C_WHITE);
i want a sinus with a good space between each period.
I checked sin function argument,it is not in degres
so sin(x*PI/180) is the good way..
I suppose you want a complete sinusoide 0 359° in full width of 128 pixels
do
Code:
char x1,y1 = 0;
float x,y;
float dummy;
do
{
x= (float)x1*360.0/128; // to show the sinus in correct place along X axis
y=sin(x*3.14159/180.0);
// scale value on Y axis .. because sinus allways between -1 and +1
// offest 32 and range +-30 around the offset
dummy=y * 30.0 +32.0;
y1=(int)dummy;
T6963C_dot(x1, y1, T6963C_WHITE);
x1++;
}
while(x1<128);
while(1); // terminé
if you want to see more sinusoide, change :
F1=(float)j1*360.0/(128.0*Nb_of_sinusoide);
but figure will be not so sinusoidale with more periodes. (step between points)
Y scale is 64
midle is 32 as the offset
sinus can evoluate from -1 to +1
so to reach the top or the bottom of display (Y axis)
you can add +1*30 or substract -1*30 from the offset
maybe you can multiply by 31 instead of 30
but not 32 because 32+32=64 and i think the Y range of display is 0 to 63
64 overflow !
in X axis you have 128 pixel to represente 360° of One sinusoide
so the elementary step must be 360°/128
or sinus doesn't accept degre ° as argument, so multiply degre by PI()/180 = value in radiants
and after multiply the sinus value by 30 to use the maximum scaling.