I am working with a graphical LCD which has a large number of serial commands for different functions.
In an attempt to clean up my workflow and to simplify my code i have attempted to build a library, unfortunatly without too much success. I have followed the stock tutorial and compared against other libraries i have downloaded yet i cannot get mine to function.
As a secondary question, does anyone have an alternative to the arduino IDE that will allow me to edit these C based files with highlighting, as well as compiling and downloading arduino programs.
Program file:
#include <lcd.h>
lcd lcdLib()
void setup(){
}
void loop(){
}
compiler report:
In file included from sketch_apr09a.cpp:1:
C:\Users\Apothus\Documents\Arduino\libraries\LCD/lcd.h:15: error: expected unqualified-id before ')' token
sketch_apr09a:0: error: new types may not be defined in a return type
sketch_apr09a.cpp:4: note: (perhaps a semicolon is missing after the definition of '')
sketch_apr09a:0: error: two or more data types in declaration of 'setup'
sketch_apr09a:2: error: expected constructor, destructor, or type conversion before ';' token
Header file lcd.h:
//Library header for simple serial code.
#ifndef lcd
#define lcd
//attached libraries
#include "Arduino.h"
class lcd
{
public:
lcd();
void clr();
int backlight(int level);
int circle(int x, int y, int radius, int set);
void crlfTog();
void reset();
void fontTgl();
int fontMode(int mode);
int line(int xOne, int yOne, int xTwo, int yTwo, int setR);
int box(int xOne, int yOne, int xTwo, int yTwo, int setR);
int fBox(int xOne, int yOne, int xTwo, int yTwo, int setR);
int pixel(int x, int y, int setR);
void reverse();
void setX(int x);
void setY(int y);
private:
int coOrd(int xOne, int yOne, int xTwo, int yTwo, int setR);
void cmd();
}
#endif
Source file lcd.cpp
// Libarary source for simple serial code
#include "Arduino.h"
#include "lcd.h"
lcd::lcd()
{
//empty construct
}
void lcd::clr()
{
lcd.cmd(); //calls the subroutine cmd, unsure if this will work though
Serial.write((byte)0x00);
}
int lcd::backlight(int level)
{
int ok = 0;
if( level >=0 && level <=64){ //hexadecmial check
lcd.cmd();
Serial.write((byte)0x02);
Serial.write((byte)level);
ok = 1;
}
return ok;
}
int lcd::circle(int x, int y, int radius, int set) //Draw a circle on screen at point x,y with radius
{
int ok = 0;
if( x>=0 && x<= 0x7f){ // x error check, 0 if fail
if( y >= 0 && y <= 0x3f){ // y error check, 1 if fail
if( radius > 0 && radius <= 0x7F){ // radius error check, 2 if fail
if( set < 2){ // set error check, 3 if fail, 4 if all OK
lcd.cmd();
ok = 4;
Serial.write((byte)0x03);
Serial.write((byte)x);
Serial.write((byte)y);
Serial.write((byte)radius);
Serial.write((byte)set);
}
else{
ok = 3;
}
}
else{
ok = 2;
}
}
else{
ok = 1;
}
}
return ok;
}
void lcd::crlfTog() // toggle automatic carridge return and line feed
{
lcd.cmd();
Serial.write((byte)0x04);
}
void lcd::reset() //clear display and reset x&y offsets
{
lcd.cmd();
Serial.write((byte)0x06);
}
void lcd::fontTgl() //toggle between primary and alternate font
{
lcd.cmd();
Serial.write((byte)0x08);
}
int lcd::fontMode(int mode) //font draw mode setting
{
int ok = 0;
if( mode >= 0 && mode <= 7){
ok = 1;
cmd();
Serial.write((byte)0x0A);
Serial.write((byte)mode);
}
return ok;
}
int lcd::line(int xOne, int yOne, int xTwo, int yTwo, int setR) //draws a line using cartesian co-ords
{
int ok = 0;
if(coOrd(xOne, yOne, xTwo, yTwo, setR) == 1){
ok = 1;
cmd();
Serial.write((byte)0x0C);
Serial.write((byte)xOne);
Serial.write((byte)yOne);
Serial.write((byte)xTwo);
Serial.write((byte)yTwo);
Serial.write((byte)setR);
}
return ok;
}
int lcd::box(int xOne, int yOne, int xTwo, int yTwo, int setR) //draws a box, much like the others
{
int ok = 0;
if(lcd.coOrd(xOne, yOne, xTwo, yTwo, setR) == 1){ //check if valid inputs with coOrd routine
ok = 1;
cmd();
Serial.write((byte)0x0F);
Serial.write((byte)xOne);
Serial.write((byte)yOne);
Serial.write((byte)xTwo);
Serial.write((byte)yTwo);
Serial.write((byte)setR);
}
return ok;
}
int lcd::fBox(int xOne, int yOne, int xTwo, int yTwo, int setR) //draws a filled in box
{
int ok = 0;
if(lcd.coOrd(xOne, yOne, xTwo, yTwo, setR) == 1){ //check if valid inputs with coOrd routine
ok = 1;
lcd.cmd();
Serial.write((byte)0x12);
Serial.write((byte)xOne);
Serial.write((byte)yOne);
Serial.write((byte)xTwo);
Serial.write((byte)yTwo);
Serial.write((byte)setR);
}
return ok;
}
int lcd::pixel(int x, int y, int setR) //draw or clear specific pixel
{
int ok = 0;
if( x >= 0 && x <= 0x7f){
if( y>= 0 && y <= 0x3f){
if( setR ==0 | setR == 1){
ok = 1;
lcd.cmd();
Serial.write((byte)0x10);
Serial.write((byte)x);
Serial.write((byte)y);
Serial.write((byte)setR);
}
}
}
return ok;
}
void lcd::reverse() //inverts the display
{
lcd.cmd();
Serial.write((byte)0x14);
}
void lcd::setX(int x) //set x offset
{
if( x>= 0 && x<=0x7f){
lcd.cmd();
Serial.write((byte)0x18);
Serial.write((byte)x);
}
}
void lcd::setY(int y) //set y offset
{
if( y>= 0 && y<= 0x7f){
lcd.cmd();
Serial.write((byte)0x19);
Serial.write((byte)y);
}
}
void lcd::cmd() //writes the command prefix to the LCD, preceeds all command functions
{
Serial.write((byte)0x7C);
}
int lcd::coOrd(int xOne, int yOne, int xTwo, int yTwo, int steR) // tests if value passed is in range
{
int ok = 0;
if( xOne >= 0 && xOne <= 0x7F){
if( xTwo >= 0 && xTwo <= 0x7F){
if( yOne >= 0 && yOne <= 0x3F){
if( yTwo >= 0 && yTwo <= 0x3F){
if( setR == 0 | setR == 1 ){
ok = 1;
}
}
}
}
}
return ok;
}
Any advice on my code would be appreciated. It has been a long time since i have written librarys or header files. I am also unclear on the case requirements for the arduino, i know that C can be a little sensitive to case at times.