here is the code i have on the slide. i figure i have something wrong with it because i did not change anything on the arduino code and with the example it works 100% of the time while it works less that 50% of the time with my code.
/* this program is intended to create a control that operates the room lights,
the door, and a security camera. The final goal is to use bluetooth to do it wireless */
#include <SoftwareSerial.h>
void button (int left, int right , int top, int bottom, int colorA, int colorB, int colorC);// screen buttom function
void mainscreen(); // main screen menu function
int lights(int status, int intensity); //lights menu function
int lightshome=0; // lights status global variable
void setup(){
Serial.begin(9600); // begin serial
}
void loop(){
mainscreen: //mainscreen label
mainscreen();
mouseX=0;// start mouseX at 0 so the screen will wait for a screen touch on the while loop
while (mouseX == 0)//
{
gettouch();
if((mouseX < 77) && (mouseX > 2) && (mouseY < 208) && (mouseY > 131))
{
//lights:
lightshome = lights(1, 70); // initialice lights with staus (on ot off), and the intensity in case it is on
if (lightshome == 1)
goto mainscreen;
}
else
mouseX=0;
}
}
void button (int left, int right, int top, int bottom, int colorA, int colorB, int colorC)// provide left, right, top, and bottom coordinate then color specefications for the bottom
{
/* Draw the outline */
fill(colorA, colorB, colorC);
stroke(50);
rect(left, top, right-left, bottom-top);
/* draw button perimeter on white*/
stroke(255, 255, 255); //button white lines
line(left+3, top, right-3, top); //top line
line(left+3, bottom, right-3, bottom); //bottom line
line(left, top+3, left, bottom-3); //left line
line(right, top+3, right, bottom-3); //right line
/* Draw the radius corners */
stroke(255,255,255);
point(left + 2, top + 1);
point(left + 1, top + 2);
point(right - 2, top + 1);
point(right - 1, top + 2);
point(left + 2, bottom - 1);
point(left + 1, bottom - 2);
point(right - 2, bottom - 1);
point(right - 1, bottom - 2);
stroke(0, 0, 0);
point(left + 1, top + 1);
point(right - 1, top + 1);
point(left + 1, bottom - 1);
point(right - 1, bottom - 1);
stroke(255,255,255);
}
void mainscreen(void)
{
background(50,50,50); // fill the screen with gray
stroke(0, 0, 255);
text("BLUETOOTH ROOM PROJECT", 10,38,6); //print bluetooth on pixel 10,38 LETTER SIZE 6
text("By Hugo Loaiza", 10, 48);
text("Owen Wei", 28, 58);
button(2, 77, 131, 208, 0, 250, 0); //Lights button
stroke(0);
text("LIGHTS", 21, 168);
button(82, 157, 131, 208, 0, 250, 0); //Door button
stroke(0);
text("DOOR", 107, 168);
button(162, 237, 131, 208, 0, 250, 0); //Camera button
stroke(0);
text("CAMERA", 183, 168);
button(242, 317, 131, 208, 0, 250, 0); //Blank button
stroke(0);
text("NEW", 272, 168);
button(162, 237, 51, 126, 0, 250, 0); //Link button
stroke(0);
text("LINK", 190, 88);
button(242, 317, 51, 126, 0, 250, 0); //Status button
stroke(0);
text("STATUS", 262, 88);
}
int lights(int status, int intensity)
{
change: //status change label
background(50);
stroke(255);
text("LIGHTS", 10,38,10); // page title
/* Home bottom that takes back to main screen */
button(242, 318, 2, 78, 50, 50, 250);
text("HOME", 270, 38);
/* menu when lights are off */
if(status == 0) //if lights are off do the following
{
button(50, 150, 162, 238, 255, 0, 0);
stroke(255);
text("OFF", 93, 197);
button(170, 270, 162, 238, 100, 100, 100);
stroke(255);
text("ON", 218, 197);
}
else
/* menu when lights are on */
if(status == 1) //if lights are on, do the following
{
button(50, 150, 162, 238, 100, 100, 100);
stroke(255);
text("OFF", 93, 197);
button(170, 270, 162, 238, 0, 250, 0);
stroke(255);
text("ON", 218, 197);
button(20, 140, 64, 90, 0, 250, 0);
text("INTENSITY", 30, 77, 10);
button(222, 260, 95, 150, 0, 250, 0);
text("%", 253, 120);
change2: // intensity change label
button(20, 220, 95, 150, 50, 50, 50);
button(20, (20+(2*intensity)), 95, 150, 0, 250, 0);
text((short)intensity, 223, 120);
}
mouseX=0;
while(mouseX == 0) //loop to wait for menu option
{
gettouch();
/* if lights are off, then turn on and change intensity to 100% */
if((status == 0) && (mouseX > 170) && (mouseX < 270) && (mouseY > 162) && ( mouseY < 238))
{
Serial.print('A'); // write an "A" to the serial pins of the arduino to turn on the lights
delay(10);
status = 1;
intensity = 100;
goto change; // go to lights main manu
}
/* if lights are on, then turn off */
if((status == 1) && (mouseX > 50) && (mouseX < 150) && (mouseY > 162) && (mouseY < 238))
{
Serial.print('B'); // write a "B" to the serial pins of the arduino to turn off the lights
delay(10);
status = 0;
goto change; // go to lights main menu
}
/* if lights are on, then change the intensity of the lights */
if((status == 1) && (mouseX > 20) && (mouseX < 220) && (mouseY > 95) && (mouseY < 150))
{
intensity = ((mouseX - 20)/2);
goto change2; //go to intensity change lable to display de nuw intensity
}
/* exit from light menu and go to main screen */
if((mouseX > 242) && (mouseX < 318) && (mouseY > 2) && (mouseY < 78))
{
return 1;
}
else
mouseX = 0; // if get touch not valid, get mouseX = 0, so it can continue with the loop.
}
}