Commit abc4a904 authored by hark's avatar hark

libraries

parent e809e9a5
......@@ -4,3 +4,6 @@
[submodule "arduino-build"]
path = arduino-build
url = ssh://git@gitlab.net.020wireless.nl:2222/yids/arduino-build.git
[submodule "libs/AESLib"]
path = libs/AESLib
url = https://github.com/y1ds/AESLib.git
BOARD_TAG=atmega328
ARDUINO_DIR=../arduino-build/
include /usr/share/arduino/Arduino.mk
ARDUINO_LIB_PATH=../arduino-build/libraries
USER_LIB_PATH=../libs/
ARDUINO_LIBS=RadioHead SPI AESLib micro-ecc MemoryFree
include /usr/share/arduino/Arduino.mk
DEVICE_PATH = /dev/ttyUSB1
TARGET = arduino-tx
Subproject commit b00f1f83984171e1ce6ac28c50175e0a65e58232
/*
LCDI2C v0.4 3/Mar/2009 dale@wentztech.com http://wentztech.com/Radio
PORTED FOR Matrix Orbital LK162-12 display 10/Sept/2010 by Brian Brumfield, brian@thebrumfields.com
What is this?
An arduino library for use with the web4robot.com i2C LCD Display in I2C more
Uses I2c Wires interface
Uses Analog pin 4 - SDA
Uses Analog pin 5 - SCL
Usage:
see the examples folder of this library distribution.
*/
#include <Wire.h>
#include <string.h> //needed for strlen()
#include <inttypes.h>
#include "Arduino.h" //all things wiring / arduino
#include "LCDI2C_LK162-12.h"
#define LCDI2C_MAX_STRLEN 40
#define LCDI2C_PRINT_STR_DELAY 20
//--------------------------------------------------------
// (don't change here - specify on calling constructor)
//how many lines has the LCD?
int g_num_lines = 2;
int g_num_col = 16;
// Defalt address of the display
int g_i2caddress = 0x50;
int g_display = 0;
//stuff the library user might call---------------------------------
//constructor. num_lines must be 1, 2, 3, or 4 currently.
LCDI2C::LCDI2C (int num_lines,int num_col,int i2c_address,int display){
g_num_lines = num_lines;
g_num_col = num_col;
g_i2caddress = i2c_address >>1; // ** 7 bit address
g_display = display;
if (g_num_lines < 1 || g_num_lines > 4){
g_num_lines = 2;
}
if (g_num_col < 1 || g_num_col > 40){
g_num_col = 16;
}
}
// Send a command to the display that is not supported
void LCDI2C::command(int value) {
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(value);
Wire.endTransmission();
delay(CMDDELAY);
}
// Write Start-Up Screen
void LCDI2C::writeStartUpScreen(char message[32]) {
Wire.beginTransmission(g_i2caddress);
Wire.write(254); //0xFE);
Wire.write(64); //0x40);
Wire.write(message);
Wire.endTransmission();
delay(CMDDELAY);
}
//Used by the print library to get information to the display
size_t LCDI2C::write(uint8_t value) {
Wire.beginTransmission(g_i2caddress);
Wire.write(value);
Wire.endTransmission();
delay(5);
return 0;
}
//send the clear screen command to the LCD
void LCDI2C::clear(){
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x58);
Wire.endTransmission();
delay(CMDDELAY);
}
//send the Home Cursor command to the LCD ********** Not Working ***************
void LCDI2C::home(){
setCursor(0,0); // The command to home the cursor does not work on the version of the dislay I have
// So we do it this way.
}
//Turn the LCD ON
void LCDI2C::on(int value){
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x42);
Wire.write(value);
Wire.endTransmission();
delay(CMDDELAY);
}
// Turn the LCD OFF
void LCDI2C::off(){
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x46);
Wire.endTransmission();
delay(CMDDELAY);
}
//Turn the Underline Cursor ON
void LCDI2C::cursor_on(){
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x4A);
Wire.endTransmission();
delay(CMDDELAY);
}
//Turn the Underline Cursor OFF
void LCDI2C::cursor_off(){
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x4B);
Wire.endTransmission();
delay(CMDDELAY);
}
//Turn the Underline Cursor ON
void LCDI2C::blink_on(){
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x53);
Wire.endTransmission();
delay(CMDDELAY);
}
//Turn the Underline Cursor OFF
void LCDI2C::blink_off(){
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x54);
Wire.endTransmission();
delay(CMDDELAY);
}
//Move the cursor left 1 space
void LCDI2C::left(){
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x43);
Wire.endTransmission();
delay(CMDDELAY);
}
//Move the cursor right 1 space
void LCDI2C::right(){
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x4D);
Wire.endTransmission();
delay(CMDDELAY);
}
// initiatize lcd after a short pause
//while there are hard-coded details here of lines, cursor and blink settings, you can override these original settings after calling .init()
void LCDI2C::init () {
delay(1000);
Wire.begin();
on(5);
clear();
blink_off();
cursor_off();
home();
}
void LCDI2C::setCursor(int line_num, int x){
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x47);
Wire.write(line_num);
Wire.write(x);
Wire.endTransmission();
delay(POSDELAY);
}
int LCDI2C::keypad (){
int data = 0;
// Send Keypad read command
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x26);
Wire.endTransmission();
delay(CMDDELAY);
// Connect to device and request byte
Wire.beginTransmission(g_i2caddress);
Wire.requestFrom(g_i2caddress, 1);
if (Wire.available()) {
data = Wire.read();
}
return data;
}
unsigned char LCDI2C::init_bargraph(unsigned char graphtype)
{
switch (graphtype)
{
case LCDI2C_THICK_VERTICAL_BAR_GRAPH:
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x76);
Wire.endTransmission();
break;
case LCDI2C_THIN_VERTICAL_BAR_GRAPH:
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x73);
Wire.endTransmission();
break;
case LCDI2C_HORIZONTAL_BAR_GRAPH:
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x68);
Wire.endTransmission();
break;
case LCDI2C_HORIZONTAL_LINE_GRAPH:
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x16);
Wire.write(0x01);
Wire.endTransmission();
break;
default:
return 1;
}
return 0;
}
void LCDI2C::draw_horizontal_graph(unsigned char row, unsigned char column, unsigned char len, unsigned char pixel_col_end)
{
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x7C);
Wire.write(row);
Wire.write(column);
Wire.write(len);
Wire.write(pixel_col_end);
Wire.endTransmission();
}
void LCDI2C::draw_vertical_graph(unsigned char row, unsigned char column, unsigned char len, unsigned char pixel_row_end)
{
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x3D);
Wire.write(row);
Wire.write(column);
Wire.write(len);
Wire.write(pixel_row_end);
Wire.endTransmission();
}
void LCDI2C::load_custom_character(unsigned char char_num, unsigned char *rows)
{
unsigned char i;
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x4E);
Wire.write(char_num);
for (i = 0; i < LCDI2C_CUSTOM_CHAR_SIZE; i++)
Wire.write(rows[i]);
Wire.endTransmission();
}
unsigned char LCDI2C::set_backlight_brightness(unsigned char new_val)
{
if ((new_val < LCDI2C_MIN_BRIGHTNESS)
|| (new_val > LCDI2C_MAX_BRIGHTNESS))
return LCDI2C_VALUE_OUT_OF_RANGE;
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x99);
Wire.write(new_val);
Wire.endTransmission();
return 0;
}
unsigned char LCDI2C::set_contrast(unsigned char new_val)
{
if ((new_val < LCDI2C_MIN_CONTRAST)
|| (new_val > LCDI2C_MAX_CONTRAST))
return LCDI2C_VALUE_OUT_OF_RANGE;
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x50);
Wire.write(new_val);
Wire.endTransmission();
return 0;
}
// Overload
void LCDI2C::printstr(const char c[])
{
byte len;
while (*c)
{
len = min(strlen(c), LCDI2C_MAX_STRLEN);
Wire.beginTransmission(g_i2caddress);
Wire.write(0xFE);
Wire.write(0x15);
Wire.write(len);
while (len--)
Wire.write(*c++);
Wire.endTransmission();
if (*c)
delay(LCDI2C_PRINT_STR_DELAY); // More to send. Wait a bit
}
}
#ifndef LCDI2Ct_h
#define LCDI2C_h
#define CMDDELAY 8 // Delay to wait after sending commands;
#define POSDELAY 8 // Long delay required by Position command
#define CHARDELAY 0
#define LCDI2C_MIN_BRIGHTNESS 0
#define LCDI2C_MAX_BRIGHTNESS 250
#define LCDI2C_VALUE_OUT_OF_RANGE 1
#define LCDI2C_MIN_CONTRAST 0
#define LCDI2C_MAX_CONTRAST 100
#include <inttypes.h>
#include "Print.h"
class LCDI2C : public Print {
public:
//LCDI2C(int num_lines,int num_col,int i2c_address,int display);
LCDI2C(int,int,int,int);
void command(int value);
void writeStartUpScreen(char message[32]);
void init();
virtual size_t write(uint8_t);
void clear();
void home();
void on(int value);
void off();
void cursor_on();
void cursor_off();
void blink_on();
void blink_off();
void left();
void right();
int keypad();
// Overload the Print class function for strings because
// the base class implementation causes problems by doing
// an I2C I/O for every character
void printstr(const char[]);
void setCursor(int line_num, int x);
// Values for graphtype in calls to init_bargraph
#define LCDI2C_THIN_VERTICAL_BAR_GRAPH 1 // **
#define LCDI2C_THICK_VERTICAL_BAR_GRAPH 2 // **
#define LCDI2C_HORIZONTAL_BAR_GRAPH 3
#define LCDI2C_HORIZONTAL_LINE_GRAPH 4
unsigned char init_bargraph(unsigned char graphtype);
void draw_horizontal_graph(unsigned char row, unsigned char column, unsigned char len, unsigned char pixel_col_end);
void draw_vertical_graph(unsigned char row, unsigned char column, unsigned char len, unsigned char pixel_col_end);
#define LCDI2C_NUM_CUSTOM_CHARS 8
#define LCDI2C_CUSTOM_CHAR_SIZE 8
void load_custom_character(unsigned char char_num, unsigned char *rows);
unsigned char set_backlight_brightness(unsigned char new_val);
unsigned char set_contrast(unsigned char new_val);
private:
};
#endif
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf320
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww17000\viewh12540\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural
\f0\fs24 \cf0 This is a library I put together to use the web4robot.com lcd display in I2C mode.\
** Ported to Matrix Orbital LK162-12 display br Brian Brumfield brian@thebrumfields.com 10/Sept/2010\
\
I have no financial interest in web4robot.com, I purchased one of their displays on e-bay to experiment with.\
\
I used the code I found e for the arduino-4bitlcd libary from http://code.google.com/p/arduino-4bitlcd/ as a place to start\
\
It uses the standard Arduino I2c Wires interface and the following pins\
\
Uses Analog pin 4 - SDA\
Uses Analog pin 5 - SCL\
\
The LCD and keypad are supported. The interrupt pin for the keypad is not supported by this version of the library.\
\
Graphing functions contributed to the library by Ran Talbott\
\
\
---------\
\
\
Init with \
\
** LCDI2C lcd = LCDI2C(2,16,0x50,0); // Where number of lines = 2, Columns = 16 and 0x4C is the i2c address of the display, type of display(Future Use)\
\
\
The following commands are available for within the library.\
\
\
init() Init the LCD and library functions, Clears the display, turns off the cursors\
\
command(command) Write a command not supported yet in the library to the display\
\
position(Row, Column) Move the cursor to position valid range is Row[0-3], Column[0,19]\
\
setCursor(Row,Column) Same as position\
\
print(val) Uses the inherited print command so you can do things like lcd.print(int,DEC);\
\
println(val) Uses the inherited print command so you can do things like lcd.print(int,DEC);\
\
printstr(string) Print a string to the display\
\
write(byte) Raw write a single byte to the display\
\
clear() Clear the display and place the cursor at 0,0\
\
home() Home the cursor to 0,0 but do not clear the display\
\
**on(timeout) Turn the LCD display on, and specify duration for backlight (0 = always on)\
\
off() Turn the LCD display off (not backlight does not go off)\
\
cursor_on() Turn the blinking line cursor on\
\
cursor_off() Turn the blinking line cursor off\
\
blink_on() Turn the blinking block cursor on\