Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MARY_CAMERA NokiaLCD mbed
main.cpp
- Committer:
- okano
- Date:
- 2014-02-13
- Revision:
- 0:1062142e5718
- Child:
- 1:ce27bc7b44d4
File content as of revision 0:1062142e5718:
/** A sample app of MARMEX_OB OLED screen drawing library * * @author Tedd * @version 0.5 * @date 07-Apr-2011 * * Released under the MIT License: http://mbed.org/license/mit * * MARMEX_OB_oled OLED screen drawing library for mbed * This code has been written based on sample code and advises * from Ochiai-san (Marutsu-Elec). Thank you! * * To build this code, "NokiaLCD" and "mbed" libraries are needed to be imported in a project. * NokiaLCD library : http://mbed.org/users/simon/libraries/NokiaLCD/ */ #include "mbed.h" #include "MARMEX_OB_oled.h" #define PARAM_NUM 99 #define CAM_I2C_ADDR 0x42 const char param[2][PARAM_NUM] = { { 0x01,0x02,0x03,0x0c,0x0e,0x0f,0x11,0x12,0x15,0x16,0x17,0x18,0x19,0x1a,0x1e,0x21,0x22, 0x29,0x32,0x33,0x34,0x35,0x37,0x38,0x39,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x41, 0x43,0x44,0x45,0x46,0x47,0x48,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53, 0x54,0x56,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x69,0x6a,0x6b,0x6c,0x6d,0x6e, 0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x8d,0x8e,0x8f,0x90, 0x91,0x96,0x96,0x97,0x98,0x99,0x9a,0x9a,0x9b,0x9c,0x9d,0x9e,0xa2,0xa4,0xb0, 0xb1,0xb2,0xb3,0xb8,0xc8,0xc9 }, { 0x40,0x60,0x02,0x0c,0x61,0x4b,0x81,0x04 ,0x00,0x02,0x39,0x03,0x03,0x7b,0x37,0x02,0x91, 0x07,0x80,0x0b,0x11,0x0b,0x1d,0x71,0x2a,0x12,0x78,0xc3,0x11,0x00,0xd0,0x08,0x38, 0x0a,0xf0,0x34,0x58,0x28,0x3a,0x09,0x00,0x40,0x20,0x80,0x80,0x00,0x22,0x5e, 0x80,0x40,0x9e,0x88,0x88,0x44,0x67,0x49,0x0e,0x00,0x40,0x0a,0x0a,0x55,0x11, 0x9f,0x3a,0x35,0x11,0xf1,0x10,0x05,0xe1,0x01,0x04,0x01,0x4f,0x00,0x00,0x00, 0x00,0x00,0x00,0x30,0x20,0x30,0x00,0x84,0x29,0x03,0x4c,0x3f,0x52,0x88,0x84, 0x0c,0x0e,0x82,0x0a,0xf0,0x60 } }; MARMEX_OB_oled oled1( p5, p7, p20, p16, p15 ); // mosi, sclk, cs, rst, power_control -- maple-mini-type-b-slot1 void init_camera( void ) { I2C i2c( p28, p27 ); for ( int i = 0; i < PARAM_NUM; i++ ) { i2c.start(); i2c.write( CAM_I2C_ADDR ); i2c.write( param[ 0 ][ i ] ); i2c.write( param[ 1 ][ i ] ); i2c.stop(); wait_ms( 20 ); } } SPI spi( p5, p6, p7 ); DigitalOut cs2( p22 ); int send_spi2( char data ) { int tmp; cs2 = 0; tmp = spi.write( data ); cs2 = 1; return ( tmp ); } int main() { int my_address; short buf[ 128 ]; int c; cs2 = 1; init_camera(); spi.format(8); spi.frequency( 1000000 ); while ( 1 ) { send_spi2( 0x03 ); send_spi2( 0x01 ); send_spi2( 0x84 ); while ( !(c = send_spi2( 0x00 ) & 0x1) ) { printf( "val = 0x%02X\r\n", c ); } printf( "camera ready\r\n" ); my_address = 24 * 2 + 176 * 8 * 2; for ( int y = 0; y < 128; y++ ) { send_spi2( 0x00 ); send_spi2( (my_address >> 0) & 0xFF ); send_spi2( 0x01 ); send_spi2( (my_address >> 8) & 0xFF ); send_spi2( 0x02 ); send_spi2( (my_address >> 16) & 0xFF ); my_address += 176 * 2; for( int x = 0; x < 128; x++ ) { buf[ x ] = (send_spi2( 0xA8 ) << 8) | send_spi2( 0xA8 ); } oled1.blit565( 0, y, 128, 1, buf ); } send_spi2( 0x03 ); send_spi2( 0x00 ); send_spi2( 0x84 ); while ( !(send_spi2( 0x84 ) & 0x1) ) ; printf( "loop done\r\n" ); } oled1.background( 0x000000 ); oled1.cls(); int colorbar_width = MARMEX_OB_oled::WIDTH / 8; for ( int i = 0; i < 8; i++ ) oled1.fill( colorbar_width * i, 0, colorbar_width, MARMEX_OB_oled::HEIGHT, ((i & 0x4) ? 0xFF0000 : 0x000000) | ((i & 0x2) ? 0x00FF00 : 0x000000) | ((i & 0x1) ? 0x0000FF : 0x000000) ); oled1.fill( 50, 50, 64, 64, 0xCCCCCC );; oled1.locate( 0, 3 ); oled1.printf( "Hello World!" ); oled1.locate( 0, 4 ); oled1.printf( "SPI = %s", MERMEX_OB_SPI_MODE_STR ); for (int i = 0; i < MARMEX_OB_oled::WIDTH; i++ ) { oled1.pixel( i, 80 + sin( (float)i / 5.0 ) * 10, 0x000000 ); } short p[3][ 128 ] = { { 0xF800 }, {0x07E0}, { 0x001F } }; for ( int i = 0; i < 128; i++ ) p[ 0 ][ i ] = 0xF800; for ( int i = 0; i < 128; i++ ) p[ 1 ][ i ] = 0x07E0; for ( int i = 0; i < 128; i++ ) p[ 2 ][ i ] = 0x001F; int count = 0; while ( 1 ) { for ( int i = 0; i < 128; i++ ) { oled1.blit565( 0, i, 128, 1, p[ count % 3 ] ); } count++; } }