128x64 oled
Revision 0:1ec2545f0516, committed 2014-04-01
- Comitter:
- loovee
- Date:
- Tue Apr 01 07:01:20 2014 +0000
- Commit message:
- watch
Changed in this revision
SeeedOLED.cpp | Show annotated file Show diff for this revision Revisions of this file |
SeeedOLED.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 1ec2545f0516 SeeedOLED.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SeeedOLED.cpp Tue Apr 01 07:01:20 2014 +0000 @@ -0,0 +1,86 @@ +/* + SeeedOLED.cpp - SSD130x OLED Driver Library + 2011 Copyright (c) Seeed Technology Inc. All right reserved. + + Author: Visweswara R + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include <mbed.h> +#include "SeeedOLED.h" + +// 8x8 Font ASCII 32 - 127 Implemented +// Users can modify this to support more characters(glyphs) +// BasicFont is placed in code memory. + +extern I2C i2c; +void SeeedOLED::init(void) +{ + sendCommand(SeeedOLED_Display_Off_Cmd); //display off + wait_ms(5); + sendCommand(SeeedOLED_Display_On_Cmd); //display on + wait_ms(5); + sendCommand(SeeedOLED_Normal_Display_Cmd); //Set Normal Display (default) +} + +void SeeedOLED::sendCommand(unsigned char command) +{ + unsigned char dta[] = {SeeedOLED_Command_Mode, command}; + i2c.write(SeeedOLED_Address<<1, (const char *)dta, 2); +} + +void SeeedOLED::setBrightness(unsigned char Brightness) +{ + sendCommand(SeeedOLED_Set_Brightness_Cmd); + sendCommand(Brightness); +} + +void SeeedOLED::setHorizontalMode() +{ + addressingMode = HORIZONTAL_MODE; + sendCommand(0x20); //set addressing mode + sendCommand(0x00); //set horizontal addressing mode +} + +void SeeedOLED::setPageMode() +{ + addressingMode = PAGE_MODE; + sendCommand(0x20); //set addressing mode + sendCommand(0x02); //set page addressing mode +} + + +void SeeedOLED::setTextXY(unsigned char Row, unsigned char Column) +{ + sendCommand(0xB0 + Row); //set page address + sendCommand(0x00 + (8*Column & 0x0F)); //set column lower address + sendCommand(0x10 + ((8*Column>>4)&0x0F)); //set column higher address +} + +void SeeedOLED::sendData(unsigned char Data) +{ + unsigned char dta[] = {SeeedOLED_Data_Mode, Data}; + + i2c.write(SeeedOLED_Address<<1, (const char*)dta, 2); +} + + +void SeeedOLED::setNormalDisplay() +{ + sendCommand(SeeedOLED_Normal_Display_Cmd); +} + +SeeedOLED oled; // Preinstantiate Objects
diff -r 000000000000 -r 1ec2545f0516 SeeedOLED.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SeeedOLED.h Tue Apr 01 07:01:20 2014 +0000 @@ -0,0 +1,95 @@ +/* + SeeedOLED.h - SSD130x OLED Driver Library + 2011 Copyright (c) Seeed Technology Inc. All right reserved. + + Author: Visweswara R + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef SeeedOLED_data_H +#define SeeedOLED_data_H + + + +#define SeeedOLED_Max_X 127 //128 Pixels +#define SeeedOLED_Max_Y 63 //64 Pixels + +#define PAGE_MODE 01 +#define HORIZONTAL_MODE 02 + + +#define SeeedOLED_Address 0x3c // 0x3c +#define SeeedOLED_Command_Mode 0x80 +#define SeeedOLED_Data_Mode 0x40 +#define SeeedOLED_Display_Off_Cmd 0xAE +#define SeeedOLED_Display_On_Cmd 0xAF +#define SeeedOLED_Normal_Display_Cmd 0xA6 +#define SeeedOLED_Inverse_Display_Cmd 0xA7 +#define SeeedOLED_Activate_Scroll_Cmd 0x2F +#define SeeedOLED_Dectivate_Scroll_Cmd 0x2E +#define SeeedOLED_Set_Brightness_Cmd 0x81 + +#define Scroll_Left 0x00 +#define Scroll_Right 0x01 + +#define Scroll_2Frames 0x7 +#define Scroll_3Frames 0x4 +#define Scroll_4Frames 0x5 +#define Scroll_5Frames 0x0 +#define Scroll_25Frames 0x6 +#define Scroll_64Frames 0x1 +#define Scroll_128Frames 0x2 +#define Scroll_256Frames 0x3 + + +class SeeedOLED { + +public: + +char addressingMode; + + +void init(void); + +void setNormalDisplay(); +void setInverseDisplay(); + +void sendCommand(unsigned char command); +void sendData(unsigned char Data); + +void setPageMode(); +void setHorizontalMode(); + +void setTextXY(unsigned char Row, unsigned char Column); +void clearDisplay(); +void setBrightness(unsigned char Brightness); +void putChar(unsigned char c); +void putString(const char *String); +unsigned char putNumber(long n); +unsigned char putFloat(float floatNumber,unsigned char decimal); +unsigned char putFloat(float floatNumber); +void drawBitmap(unsigned char *bitmaparray,int bytes); + +void setHorizontalScrollProperties(bool direction,unsigned char startPage, unsigned char endPage, unsigned char scrollSpeed); +void activateScroll(); +void deactivateScroll(); + +}; + +extern SeeedOLED oled; // SeeedOLED object + +#endif +