Code:
#include "U8glib.h"
U8GLIB_NHD_C12864 u8g(13, 11, 10, 9);
int val; // Y value (Read from the Analog input)
int xPos = 0; // X position
int prevXPos = 0; // Previous x position
int scanVal[128]; // Array to hold the graphs values as it scans.
int xDraw; // Used to
//--------------------------------------------
void drawText(void) {
val = analogRead(A0);// Poll ADC
val = map(val,0,1023,63,0);// Scale things down to fit the vertical pixel count of the LCD.
scanVal[xPos] = val;// Write the Y value to the appropriate element (X value).
u8g.setPrintPos(50, 63);// Set Cursor.
u8g.print("Y");
u8g.print(val);// Print out the Y value.
u8g.setPrintPos(20, 63);// Set Cursor.
u8g.print("X");
u8g.print(xPos);// Print out the X value.
}
//--------------------------------------------
void drawScan(void) {// This function cycles 128 times per update to draw the full scan of the line.
val = scanVal[xDraw];// Pull the Y value from the appropriate element.
u8g.drawPixel(xDraw,val);// Set a pixel.
xDraw++;// Increment the column position (X value).
}// End of scan
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void setup(void) {
u8g.setRot180();// Flip screen
u8g.setFont(u8g_font_6x10r);// Set Font
pinMode(7,OUTPUT);
}
void loop(void) {
u8g.firstPage();
do {
drawText();
xDraw = 0;
do
{
drawScan();
}
while(xDraw <= 127); // Loop to draw every column of the array.
}
while( u8g.nextPage() );
if(xPos == 127) xPos = 0; // Reset X to 0 when it reaches the last column on the screen.
else xPos++; // Increment X position
}// End Void Loop()
U8GLIB_NHD_C12864 u8g(13, 11, 10, 9);
int val; // Y value (Read from the Analog input)
int xPos = 0; // X position
int prevXPos = 0; // Previous x position
int scanVal[128]; // Array to hold the graphs values as it scans.
int xDraw; // Used to
//--------------------------------------------
void drawText(void) {
val = analogRead(A0);// Poll ADC
val = map(val,0,1023,63,0);// Scale things down to fit the vertical pixel count of the LCD.
scanVal[xPos] = val;// Write the Y value to the appropriate element (X value).
u8g.setPrintPos(50, 63);// Set Cursor.
u8g.print("Y");
u8g.print(val);// Print out the Y value.
u8g.setPrintPos(20, 63);// Set Cursor.
u8g.print("X");
u8g.print(xPos);// Print out the X value.
}
//--------------------------------------------
void drawScan(void) {// This function cycles 128 times per update to draw the full scan of the line.
val = scanVal[xDraw];// Pull the Y value from the appropriate element.
u8g.drawPixel(xDraw,val);// Set a pixel.
xDraw++;// Increment the column position (X value).
}// End of scan
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void setup(void) {
u8g.setRot180();// Flip screen
u8g.setFont(u8g_font_6x10r);// Set Font
pinMode(7,OUTPUT);
}
void loop(void) {
u8g.firstPage();
do {
drawText();
xDraw = 0;
do
{
drawScan();
}
while(xDraw <= 127); // Loop to draw every column of the array.
}
while( u8g.nextPage() );
if(xPos == 127) xPos = 0; // Reset X to 0 when it reaches the last column on the screen.
else xPos++; // Increment X position
}// End Void Loop()
I couldn't get it to draw lines instead of points. It would visibly buffer the pages.
I'm actually running my display in parallel mode with a different library to see if I can get it to work right. It works well, but I have to figure out how to set the contrast since it is not set up to be externally controlled like KS0108 driven displays. I think I've found out how to adjust it in the datasheet, though.
- Muhammad.
) It of course doesn't work since this library (to my understanding) rewrites the entire screen each time it cycles rather than just the pixels specified in the functions. Instead, it just scans a single pixel.