|
楼主 |
发表于 2012-3-11 16:04:41
|
显示全部楼层
本帖最后由 thomas 于 2015-2-2 23:37 编辑
编辑帖子老出错。先说接线图。
由于OLED多工作于3.3v,因此为了匹配输入端电压,用了一块缓冲器CD4050.
介绍
CD4050是非反相六缓冲器,具有仅用一电源电压(VCC)进行逻辑电平转换的特征。用作逻辑电平转换时,输入高电平电压(VIH)超过电源电压VCC。该器件主要用作COS/MOS到DTL/TTL的转换器,能直接驱动两个DTL/TTL负载。16引出端是空脚 ,与内部电路无连接。
接线
Arduino IO端口 CD4050引脚
DIGITAL
9 ---------------------- 14
10 ---------------------- 11
11 ---------------------- 9
12 ---------------------- 5
13 ---------------------- 3
+5v ------------------ 1
GND ------------------- 8
LM096-128064引脚/ 功能 CD4050引脚
1 ------VDD--------------------------- 1
2 ------VSS---------------------------- 8
3 ------- CS# -------------------------- 4
4 --------RES# ----------------------- 2
5 --------D/C#------------------------ 10
8--------- D0 ----------------------- 12
9 -------- D1 -------------------------- 15
代码 - #define OLED_DC 11
- #define OLED_CS 12
- #define OLED_CLK 10
- #define OLED_MOSI 9
- #define OLED_RESET 13
- #include <SSD1306.h>
- SSD1306 oled(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
- #define NUMFLAKES 10
- #define XPOS 0
- #define YPOS 1
- #define DELTAY 2
- #define LOGO16_GLCD_HEIGHT 16
- #define LOGO16_GLCD_WIDTH 16
- static unsigned char __attribute__ ((progmem)) logo16_glcd_bmp[]={
- 0x30, 0xf0, 0xf0, 0xf0, 0xf0, 0x30, 0xf8, 0xbe, 0x9f, 0xff, 0xf8, 0xc0, 0xc0, 0xc0, 0x80, 0x00,
- 0x20, 0x3c, 0x3f, 0x3f, 0x1f, 0x19, 0x1f, 0x7b, 0xfb, 0xfe, 0xfe, 0x07, 0x07, 0x07, 0x03, 0x00, };
- void setup() {
- Serial.begin(9600);
-
- // If you want to provide external 7-9V VCC, uncomment next line and comment the one after
- //oled.ssd1306_init(SSD1306_EXTERNALVCC);
-
- // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
- oled.ssd1306_init(SSD1306_SWITCHCAPVCC);
- // init done
-
- oled.display(); // show splashscreen
- delay(2000);
- oled.clear(); // clears the screen and buffer
- // Fill screen
- oled.fillrect(0, 0, SSD1306_LCDWIDTH-1, SSD1306_LCDHEIGHT-1, WHITE);
- oled.display();
- delay(2000);
- // draw a single pixel
- oled.setpixel(10, 10, WHITE);
- oled.display();
- delay(2000);
- oled.clear();
- // draw many lines
- testdrawline();
- oled.display();
- delay(2000);
- oled.clear();
- // draw rectangles
- testdrawrect();
- oled.display();
- delay(2000);
- oled.clear();
- // draw multiple rectangles
- testfillrect();
- oled.display();
- delay(2000);
- oled.clear();
- // draw mulitple circles
- testdrawcircle();
- oled.display();
- delay(2000);
- oled.clear();
- // draw a white circle, 10 pixel radius, at location (32,32)
- oled.fillcircle(32, 32, 10, WHITE);
- oled.display();
- delay(2000);
- oled.clear();
- // draw the first ~12 characters in the font
- testdrawchar();
- oled.display();
- delay(2000);
- oled.clear();
- // draw a string at location (0,0)
- oled.drawstring(0, 0, "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation");
- oled.display();
- delay(2000);
- oled.clear();
- // miniature bitmap display
- oled.drawbitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
- oled.display();
- // invert the display
- oled.ssd1306_command(SSD1306_INVERTDISPLAY);
- delay(1000);
- oled.ssd1306_command(SSD1306_NORMALDISPLAY);
- delay(1000);
- // draw a bitmap icon and 'animate' movement
- testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
- }
- void loop()
- {
- for (uint8_t i=0; i<SSD1306_LCDWIDTH; i++) {
- for (uint8_t j=0; j<SSD1306_LCDHEIGHT; j++) {
- oled.setpixel(i, j, WHITE);
- oled.display();
- }
- }
-
- }
- void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
- uint8_t icons[NUMFLAKES][3];
- srandom(666); // whatever seed
-
- // initialize
- for (uint8_t f=0; f< NUMFLAKES; f++) {
- icons[f][XPOS] = random() % SSD1306_LCDWIDTH;
- icons[f][YPOS] = 0;
- icons[f][DELTAY] = random() % 5 + 1;
-
- Serial.print("x: ");
- Serial.print(icons[f][XPOS], DEC);
- Serial.print(" y: ");
- Serial.print(icons[f][YPOS], DEC);
- Serial.print(" dy: ");
- Serial.println(icons[f][DELTAY], DEC);
- }
- while (1) {
- // draw each icon
- for (uint8_t f=0; f< NUMFLAKES; f++) {
- oled.drawbitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
- }
- oled.display();
- delay(200);
-
- // then erase it + move it
- for (uint8_t f=0; f< NUMFLAKES; f++) {
- oled.drawbitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK);
- // move it
- icons[f][YPOS] += icons[f][DELTAY];
- // if its gone, reinit
- if (icons[f][YPOS] > SSD1306_LCDHEIGHT) {
- icons[f][XPOS] = random() % SSD1306_LCDWIDTH;
- icons[f][YPOS] = 0;
- icons[f][DELTAY] = random() % 5 + 1;
- }
- }
- }
- }
- void testdrawchar(void) {
- for (uint8_t i=0; i < 168; i++) {
- oled.drawchar((i % 21) * 6, i/21, i);
- }
- }
- void testdrawcircle(void) {
- for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=2) {
- oled.drawcircle(63, 31, i, WHITE);
- }
- }
- void testdrawrect(void) {
- for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=2) {
- oled.drawrect(i, i, SSD1306_LCDWIDTH-i, SSD1306_LCDHEIGHT-i, WHITE);
- }
- }
- void testfillrect(void) {
- for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i++) {
- // alternate colors for moire effect
- oled.fillrect(i, i, SSD1306_LCDWIDTH-i, SSD1306_LCDHEIGHT-i, i%2);
- }
- }
- void testdrawline() {
- for (uint8_t i=0; i<SSD1306_LCDWIDTH; i+=4) {
- oled.drawline(0, 0, i, SSD1306_LCDHEIGHT-1, WHITE);
- oled.display();
- }
- for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=4) {
- oled.drawline(0, 0, SSD1306_LCDWIDTH-1, i, WHITE);
- oled.display();
- }
- delay(1000);
- for (uint8_t i=0; i<SSD1306_LCDWIDTH; i+=4) {
- oled.drawline(i, SSD1306_LCDHEIGHT-1, 0, 0, BLACK);
- oled.display();
- }
- for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=4) {
- oled.drawline(SSD1306_LCDWIDTH - 1, i, 0, 0, BLACK);
- oled.display();
- }
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|