I got my application below to compile, though it wasn't passing the variables back to its caller to determine which screen graphic to display. I figured the data wasn't actually global, so I changed the button press info to a boolean array...now the thing won;t compile despite hours trying to figure out what i am doing wrong. Can anybody lend assistance? Thanks in advance.
/*
6 button ButtonBitmap.pde
*/
#include "U8glib.h"
//define the pins for the touch screen
#define xLow A0//14
#define xHigh A1//15
#define yLow A2//16
#define yHigh A3//17
#define workbench 0;
#define center 1;
#define leftwall 2;
#define rightwall 3;
#define alloff 4;
#define allon 5;
boolean button[6];
//Declare functions
int get_xy(void);
void whichbuttonpressed(int,int);
int draw(void);
int x,y;
// setup u8g object, please remove comment from one of the following constructor calls
U8GLIB_LC7981_160X80 u8g(22,23,24,25,26,27,28,29,30,31,32,33,34);//change these pin assignments...
//d0,d1,d2,d3,d4,d5,d6,d7,en,cs1,di=rs,rw,res. cs2 is unneeded,reset is recommended to connect
const uint8_t button_bitmap[] PROGMEM = {
0x00,0x00,0x00,0x00,
0x01,0xFF,0xFF,0x80,
//truncated
0x00,0x00,0x00,0x00};
const uint8_t button_on_bitmap[] PROGMEM = {
0x00,0x00,0x00,0x00,
0x01,0xFF,0xFF,0x80,
//truncated
0x00,0x00,0x00,0x00};
void setup(void) {
}
// *******************************************************************************************************
int draw(void) { //draw 4 columns of 2 rows of buttons - text below
// graphic commands to redraw the complete screen should be placed here
//Set this up for hangar lights. 5 buttons for light banks. Rotate screen to portrait view.
u8g.setRot270(); //ok now we are rotated -90 degrees, so change the button positions.
int get_xy();
whichbuttonpressed(x,y);
//workbench=1; //test works from here
if (button[allon])
button[workbench]=1; button[center] =1; button[leftwall] =1; button[rightwall] = 1;
button[alloff] = 0;
if (button[alloff]) //preset all to off
button[workbench]=0; button[center]=0; button[leftwall]=0; button[rightwall]=0; button[allon]=0;
//alloff button need not show "on"
if (button[workbench])
u8g.drawBitmapP( 02, 0, 4,32, button_on_bitmap); //check for workbench button press-display on/off
else
u8g.drawBitmapP( 02, 0, 4,32, button_bitmap);
if (button[center])
u8g.drawBitmapP( 46, 0, 4,32, button_on_bitmap);
else
u8g.drawBitmapP( 46, 0, 4,32, button_bitmap);
if (button[leftwall])
u8g.drawBitmapP( 02, 55, 4,32, button_on_bitmap);
else
u8g.drawBitmapP( 02, 55, 4,32, button_bitmap);
if (button[rightwall])
u8g.drawBitmapP( 46, 55, 4,32, button_on_bitmap);
else
u8g.drawBitmapP( 46, 55, 4,32, button_bitmap);
if (button[allon])
u8g.drawBitmapP( 46,109, 4,32, button_on_bitmap);
else
u8g.drawBitmapP( 46,109, 4,32, button_bitmap);
u8g.drawBitmapP( 02, 109, 4,32, button_bitmap); //just draw "all off" button regardless of keypress
//draw button descriptors
//u8g.setFont(u8g_font_unifont);
u8g.setFont(u8g_font_5x7);
u8g.drawStr( 03, 39, "W-bench");
u8g.drawStr( 03, 46, "& Door");
u8g.drawStr( 45, 39, " Center");
//u8g.drawStr( 46, 46, "Center");
u8g.drawStr( 03, 95, " Left");
u8g.drawStr( 03, 103, " Wall");
u8g.drawStr( 45, 95, " Right");
u8g.drawStr( 47, 103, " Wall");
u8g.drawStr( 03, 148, " All Off");
// u8g.drawStr( 04, 155, " Off");
u8g.drawStr(47, 151, " All On");
} //end of draw function
// *******************************************************************************************************
// *******************************************************************************************************
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
// delay(3000);
}
// *******************************************************************************************************
// *******************************************************************************************************
// Calculate which button if any has been pressed
void whichbuttonpressed(int x,int y)
{
if (x < 85)
return;
//top of portrait screen limit-just return
if (x > 740)
return; ;//bottom bottom button limit
if (y < 140)
return; //left of buttons
if (y > 750)
return; //right of ...
if ( (x>85 && x<250) && ( y>140 && y<365 )) //top left button press?
button[workbench] = !button[workbench];
return;
//return button[workbench],button[center],button[leftwall],button[rightwall],button[alloff],button[allon];
}
//workbench=1; //this declaration changes the button to on
if ( (x>85 && x<250 ) && ( y>500 && y<750 )) //top right button?
button[center] =!button[center];
return;
if ( (x>342 & x<495) & (y>140 & y<365 )) //middle left button?
button[leftwall} =!button[leftwall];
return;
if ( (x>342 & x<495) & (y>500 & y<750) ) //middle right button?
button[rightwall] =!button[rightwall];
return;
if ( (x>590 & x<740) & ( y>140 & y<365 )) //all off button?
alloff =1;
button[workbench]=button[center]=button[leftwall]=button[rightwall]=0;
return;
if ( (x>590 & x<740) & (y>500 & y<750 )) //all on button?
allon =1;
return;
return;
}
// *******************************************************************************************************
//COntents of touchsendserial inserted below. Revised function names
//Basically using the analog pins 0,1,2,3 on an Arduino board, those pins can be both analogRead pins and digitalWrite pins(in this case:pin numbers are 14,15,16,17) depending on //setting.
//First, to read an x-coordinate value, set the pin14 as 0V(LOW) and the pin15 as 5V(HIGH), then the rest of the pins(either of 16 and 17) can be analogRead pins.
//Next, to read a y-coordinate value, set the pin16 as 0V(LOW) and the pin16 as 5V(HIGH), then read the value from either of the pin14 and the pin15.
// Reading the both value one after another then send them through a serial communication to Processing.
//70 :a minimum value when touching the left edge of the touch panel
//???? :a maxmum value when touching the right edge of the touch panel
//???? :a minimum value when touching the upper edge of the touch panel
//???? :a maxmum value when touching the lower edge of the touch panel
//
//In this example, I used a 12.1-inch(width:height=4:3) touch panel.
//When touching each edge of the touch panel, the values are like the above.
//When not touching the touch panel, you can read zero value from the analog pins because of the pull-down resistors.
//the digital output pins - already defined up top
//#define xLow A0//14
//#define xHigh A1//15
//#define yLow A2//16
//#define yHigh A3//17
int get_xy(){ //read touch screen position
//start serial communication
Serial.begin(9600);
//
//X?LOW HIGH
//set the both x-coordinate pins as digital output:one is Low the other is HIGH
pinMode(xLow,OUTPUT);
pinMode(xHigh,OUTPUT);
digitalWrite(xLow,LOW);
digitalWrite(xHigh,HIGH);
// Y LOW:the both y-coordinate pins are set to be LOW
digitalWrite(yLow,LOW);
digitalWrite(yHigh,LOW);
//Ychange the y-coordinate pins as digital input
pinMode(yLow,INPUT);
pinMode(yHigh,INPUT);
delay(10);
//?yLow?//read analog pin2(yLow pin) to get an x-coordinate value
int x=analogRead(A2);
//set the both y-coordinate pins as digital output:one is Low the other is HIGH
pinMode(yLow,OUTPUT);
pinMode(yHigh,OUTPUT);
digitalWrite(yLow,LOW);
digitalWrite(yHigh,HIGH);
//X LOW:the both x-coordinate pins are set to be LOW
digitalWrite(xLow,LOW);
digitalWrite(xHigh,LOW);
//X:change the x-coordinate pins as digital input
pinMode(xLow,INPUT);
pinMode(xHigh,INPUT);
delay(10);
//?xLow
//read analog pin0(xLow pin) to get an y-coordinate value
int y=analogRead(A0);
//if(Serial.available()>0){
//:send the values as a DEC format with a delimiter
Serial.print(x,DEC); //X:x-coordinate
Serial.print(","); //:delimiter
Serial.println(y,DEC); //Y:y-coordinate
Serial.print("/Button booleans:");
Serial.println(workbench);
//delay (1000);
//read a handshake signal from Processing and clear the buffer
Serial.read();
return x,y;
}
// *******************************************************************************************************
Moderator edit: CODE TAGS