128x64 oled

Dependents:   Xadow_Watch_OLED

Committer:
loovee
Date:
Tue Apr 01 07:01:20 2014 +0000
Revision:
0:1ec2545f0516
watch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
loovee 0:1ec2545f0516 1 /*
loovee 0:1ec2545f0516 2 SeeedOLED.cpp - SSD130x OLED Driver Library
loovee 0:1ec2545f0516 3 2011 Copyright (c) Seeed Technology Inc. All right reserved.
loovee 0:1ec2545f0516 4
loovee 0:1ec2545f0516 5 Author: Visweswara R
loovee 0:1ec2545f0516 6
loovee 0:1ec2545f0516 7 This library is free software; you can redistribute it and/or
loovee 0:1ec2545f0516 8 modify it under the terms of the GNU Lesser General Public
loovee 0:1ec2545f0516 9 License as published by the Free Software Foundation; either
loovee 0:1ec2545f0516 10 version 2.1 of the License, or (at your option) any later version.
loovee 0:1ec2545f0516 11
loovee 0:1ec2545f0516 12 This library is distributed in the hope that it will be useful,
loovee 0:1ec2545f0516 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
loovee 0:1ec2545f0516 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
loovee 0:1ec2545f0516 15 Lesser General Public License for more details.
loovee 0:1ec2545f0516 16
loovee 0:1ec2545f0516 17 You should have received a copy of the GNU Lesser General Public
loovee 0:1ec2545f0516 18 License along with this library; if not, write to the Free Software
loovee 0:1ec2545f0516 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
loovee 0:1ec2545f0516 20 */
loovee 0:1ec2545f0516 21
loovee 0:1ec2545f0516 22 #include <mbed.h>
loovee 0:1ec2545f0516 23 #include "SeeedOLED.h"
loovee 0:1ec2545f0516 24
loovee 0:1ec2545f0516 25 // 8x8 Font ASCII 32 - 127 Implemented
loovee 0:1ec2545f0516 26 // Users can modify this to support more characters(glyphs)
loovee 0:1ec2545f0516 27 // BasicFont is placed in code memory.
loovee 0:1ec2545f0516 28
loovee 0:1ec2545f0516 29 extern I2C i2c;
loovee 0:1ec2545f0516 30 void SeeedOLED::init(void)
loovee 0:1ec2545f0516 31 {
loovee 0:1ec2545f0516 32 sendCommand(SeeedOLED_Display_Off_Cmd); //display off
loovee 0:1ec2545f0516 33 wait_ms(5);
loovee 0:1ec2545f0516 34 sendCommand(SeeedOLED_Display_On_Cmd); //display on
loovee 0:1ec2545f0516 35 wait_ms(5);
loovee 0:1ec2545f0516 36 sendCommand(SeeedOLED_Normal_Display_Cmd); //Set Normal Display (default)
loovee 0:1ec2545f0516 37 }
loovee 0:1ec2545f0516 38
loovee 0:1ec2545f0516 39 void SeeedOLED::sendCommand(unsigned char command)
loovee 0:1ec2545f0516 40 {
loovee 0:1ec2545f0516 41 unsigned char dta[] = {SeeedOLED_Command_Mode, command};
loovee 0:1ec2545f0516 42 i2c.write(SeeedOLED_Address<<1, (const char *)dta, 2);
loovee 0:1ec2545f0516 43 }
loovee 0:1ec2545f0516 44
loovee 0:1ec2545f0516 45 void SeeedOLED::setBrightness(unsigned char Brightness)
loovee 0:1ec2545f0516 46 {
loovee 0:1ec2545f0516 47 sendCommand(SeeedOLED_Set_Brightness_Cmd);
loovee 0:1ec2545f0516 48 sendCommand(Brightness);
loovee 0:1ec2545f0516 49 }
loovee 0:1ec2545f0516 50
loovee 0:1ec2545f0516 51 void SeeedOLED::setHorizontalMode()
loovee 0:1ec2545f0516 52 {
loovee 0:1ec2545f0516 53 addressingMode = HORIZONTAL_MODE;
loovee 0:1ec2545f0516 54 sendCommand(0x20); //set addressing mode
loovee 0:1ec2545f0516 55 sendCommand(0x00); //set horizontal addressing mode
loovee 0:1ec2545f0516 56 }
loovee 0:1ec2545f0516 57
loovee 0:1ec2545f0516 58 void SeeedOLED::setPageMode()
loovee 0:1ec2545f0516 59 {
loovee 0:1ec2545f0516 60 addressingMode = PAGE_MODE;
loovee 0:1ec2545f0516 61 sendCommand(0x20); //set addressing mode
loovee 0:1ec2545f0516 62 sendCommand(0x02); //set page addressing mode
loovee 0:1ec2545f0516 63 }
loovee 0:1ec2545f0516 64
loovee 0:1ec2545f0516 65
loovee 0:1ec2545f0516 66 void SeeedOLED::setTextXY(unsigned char Row, unsigned char Column)
loovee 0:1ec2545f0516 67 {
loovee 0:1ec2545f0516 68 sendCommand(0xB0 + Row); //set page address
loovee 0:1ec2545f0516 69 sendCommand(0x00 + (8*Column & 0x0F)); //set column lower address
loovee 0:1ec2545f0516 70 sendCommand(0x10 + ((8*Column>>4)&0x0F)); //set column higher address
loovee 0:1ec2545f0516 71 }
loovee 0:1ec2545f0516 72
loovee 0:1ec2545f0516 73 void SeeedOLED::sendData(unsigned char Data)
loovee 0:1ec2545f0516 74 {
loovee 0:1ec2545f0516 75 unsigned char dta[] = {SeeedOLED_Data_Mode, Data};
loovee 0:1ec2545f0516 76
loovee 0:1ec2545f0516 77 i2c.write(SeeedOLED_Address<<1, (const char*)dta, 2);
loovee 0:1ec2545f0516 78 }
loovee 0:1ec2545f0516 79
loovee 0:1ec2545f0516 80
loovee 0:1ec2545f0516 81 void SeeedOLED::setNormalDisplay()
loovee 0:1ec2545f0516 82 {
loovee 0:1ec2545f0516 83 sendCommand(SeeedOLED_Normal_Display_Cmd);
loovee 0:1ec2545f0516 84 }
loovee 0:1ec2545f0516 85
loovee 0:1ec2545f0516 86 SeeedOLED oled; // Preinstantiate Objects