|
楼主 |
发表于 2012-11-23 21:26:03
|
显示全部楼层
#include <U8glib.h>
U8GLIB_ST7920_128X64 u8g(3, 9, 8, U8G_PIN_NONE);
#define AR_SIZE( a ) sizeof( a ) / sizeof( a[0] )
const int Input = A0;
int x, y = 128;
int ax, ay = 128;
int Status[128];
void setup()
{
for ( int i = 0;i < 128;i++)
{
Status[i] = 64;
}
}
void draw()
{
y = map(analogRead(Input),0,1023,63,6);
for(x = 0;x < 128;x++)
{
if (x < 127){Status[x] = Status[x+1];}else{Status[127] = y;}
u8g.drawPixel(x,Status[x]); //话波形
if (ay != Status[x])
{
u8g.drawLine(x,ay,x,Status[x]);
ax = x;ay = Status[x];
}
}
u8g.setFont(u8g_font_4x6); //写文字
u8g.drawStr(1,5,"APE Arduino Oscilloscope V0.1");
u8g.drawLine(25.6, 6, 25.6, 64); //画网格
u8g.drawLine(25.6*2, 6, 25.6*2, 64);
u8g.drawLine(25.6*3, 6, 25.6*3, 64);
u8g.drawLine(25.6*4, 6, 25.6*4, 64);
u8g.drawLine(25.6*5, 6, 25.6*5, 64);
u8g.drawLine(0, 35 - 15, 128, 35 - 15);
u8g.drawLine(0, 35, 128, 35);
u8g.drawLine(0, 35 + 15, 128, 35 + 15);
}
void loop()
{
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
} |
|