A 3-as menübe lépve a Knight Rider_2 egyszer lefut, aztán a Kinght Rider_3 ismétlődik.
Hogyan legyen a kód, hogy ebben a menüben kilépésig ismétlődjön a kettes?
[code]
/* Knight Rider 3
* --------------
*
* This example concentrates on making the visuals fluid.
*
*
* (cleft) 2005 K3, Malmo University
* @author: David Cuartielles
* @hardware: David Cuartielles, Aaron Hallborg
*/
int pinArray[] = {14, 15, 16, 42, 43, 46, 48, 49};
int count = 0;
int timer = 30;
#include <UTFT.h>
#include <UTouch.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS 8
float HLTtemp; //0x28, 0xEE, 0x6D, 0x34, 0x05, 0x00, 0x00, 0xAA
float Mashtemp; //0x28, 0x48, 0x27, 0x35, 0x05, 0x00, 0x00, 0x9F
float Boilertemp; //0x28, 0x25, 0x28, 0x35, 0x05, 0x00, 0x00, 0x79
DeviceAddress HLT = {
0x28, 0xEE, 0x6D, 0x34, 0x05, 0x00, 0x00, 0xAA };
DeviceAddress Mash = {
0x28, 0x48, 0x27, 0x35, 0x05, 0x00, 0x00, 0x9F };
DeviceAddress Boiler = {
0x28, 0x25, 0x28, 0x35, 0x05, 0x00, 0x00, 0x79 };
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
extern uint8_t SevenSeg_XXXL_Num[];
int x, y,g,menu;
UTFT myGLCD(ITDB32S,38,39,40,41);
UTouch myTouch(6,5,4,3,2);
void(* resetFunc) (void) = 0; //declare reset function @ address 0
void setup(){
for (count=0;count<8;count++) {
pinMode(pinArray[count], OUTPUT);
sensors.begin();
myGLCD.InitLCD(LANDSCAPE); // Initialize the display
myGLCD.clrScr(); // Clear the screen (black)
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(BigFont);
myGLCD.fillScr(255,255,255); // Clear the screen (White)
delay(600); //Delay to draw the image
myGLCD.clrScr(); // Clear the screen (black)
Menu1();
menu=1;
}
}
void readtemp()
{
//Call sensors.requestTemperatures() to issure a global temperature
//request to all devices on the bus
sensors.requestTemperatures(); //Send the command to get temperatures
HLTtemp = (sensors.getTempC(HLT));
Mashtemp = (sensors.getTempC(Mash));
Boilertemp = (sensors.getTempC(Boiler));
}
//Buttons coordinates
//Menu 1
//Button HLT
int x11=20; int y11=20; int x12=100; int y12=80;
//Button Mash
int x21=180; int y21=20; int x22=300; int y22=100;
//Button Boiler
int x31=20; int y31=120; int x32=150; int y32=200;
//Button Menu
int x41=180; int y41=120; int x42=300; int y42=200;
//Button G
int x51=10; int y51=10; int x52=160; int y52=220;
//Button Back
int x61=220; int y61=190; int x62=310; int y62=230;
//Front led
int x71=20; int y71=40; int x72=170; int y72=100;
//Back led
int x81=20; int y81=130; int x82=170; int y82=190;
//Button Reset
int x91=110; int y91=90; int x92=150; int y92=110;
void Menu1() // MAIN MENU
{
myGLCD.clrScr(); // Clear the screen (black)
myGLCD.setFont(BigFont);
myGLCD.setColor(0, 0, 255);
myGLCD.setBackColor(0, 0, 255);
//BUTTON Gpro
button (x11,y11,x12,y12); myGLCD.print("HLT",35,50);
//BUTTON Leds
button (x21,y21,x22,y22); myGLCD.print("Mash",210,50);
//BUTTON Volto
button (x31,y31,x32,y32); myGLCD.print("Boiler",35,150);
//BUTTON Spare
button (x41,y41,x42,y42); myGLCD.print("Menu",210,150);
//BUTTON Reset
button (x91,y91,x92,y92); myGLCD.print("RST",110,90);
menu =1;
}
void Menu2() //HLT MENU
{
myGLCD.clrScr(); // Clear the screen (black)
myGLCD.print("HLT Temp:", 20, 20);
myGLCD.setBackColor(0, 0, 255);
button (x61,y61,x62,y62); myGLCD.setFont(BigFont); myGLCD.print("Back",230,200);
resetFunc();
menu =2;
myGLCD.printNumF(HLTtemp, 1, 200, 20);
}
void Menu3() //Mash MENU
{
myGLCD.clrScr(); // Clear the screen (black)
//Front led
button (x71,y71,x72,y72);
myGLCD.setFont(BigFont); myGLCD.print("Front Led",30,70);
//Back Led
button (x81,y81,x82,y82);
myGLCD.setBackColor(0, 0, 255);
myGLCD.setFont(BigFont); myGLCD.print("Back Led",30,160);
button (x61,y61,x62,y62); myGLCD.setFont(BigFont); myGLCD.print("Back",230,200);
menu =3;
}
void Menu4() // MENU 4
{
myGLCD.clrScr(); // Clear the screen (black)
myGLCD.setFont(BigFont); myGLCD.print("Menu 4",30,70);
button (x61,y61,x62,y62); myGLCD.setFont(BigFont); myGLCD.print("Back",230,200);
menu =4;
}
void Menu5() // MENU 5
{
myGLCD.clrScr(); // Clear the screen (black)
myGLCD.setFont(BigFont); myGLCD.print("Menu 5",30,70);
button (x61,y61,x62,y62); myGLCD.setFont(BigFont); myGLCD.print("Back",230,200);
menu =5;
}
void Knight_Rider_3 ()
{
for (count=0;count<7;count++) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count + 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer*2);
}
for (count=7;count>0;count--) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count - 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer*2);
}
}
void Knight_Rider_2 ()
{
for (count=0;count<5;count++) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count + 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer*2);
}
for (count=5;count>0;count--) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count - 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer*2);
}
}
void loop() {
while (1)
{
Knight_Rider_3 ();
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if (menu ==1)
{
if ((y>=y11) && (y<=y12)) // Upper row
{
if ((x>=x11) && (x<=x12)) // Button: Gpro
{
waitForIt(x11,y11,x12,y12);
menu =2;
Menu2();
}
if ((x>=x21) && (x<=x22)) // Button: Leds
{
waitForIt(x21,y21,x22,y22);
menu =3;
Menu3();
}
}
if ((y>=y31) && (y<=y32)) // Lower row
{
if ((x>=x31) && (x<=x32)) // Button: Volto
{
waitForIt(x31,y31,x32,y32);
menu =4;
Menu4();
}
if ((x>=x41) && (x<=x42)) // Button: Spare
{
waitForIt(x41,y41,x42,y42);
menu =5;
Menu5();
}
}
}
if (menu==2)
{
myGLCD.setFont(BigFont);
delay(300);
if ((y>=y61) && (y<=y62)) // Button: Back
{
if ((x>=x61) && (x<=x62)) // Button: Back
{
waitForIt(x61,y61,x62,y62);
menu =1;
Menu1();
}
}
}
if (menu==3)
{
delay(300);
if ((y>=y61) && (y<=y62)) // Button: Back
{
if ((x>=x61) && (x<=x62)) // Button: Back
{
waitForIt(x61,y61,x62,y62);
menu =1;
Menu1();
}
}
Knight_Rider_2 ();
}
if (menu==4)
{
if ((y>=y61) && (y<=y62)) // Button: Back
{
if ((x>=x61) && (x<=x62)) // Button: Back
{
waitForIt(x61,y61,x62,y62);
menu =1;
Menu1();
}
}
}
if (menu==5)
{
if ((y>=y61) && (y<=y62)) // Button: Back
{
if ((x>=x61) && (x<=x62)) // Button: Back
{
waitForIt(x61,y61,x62,y62);
menu =1;
Menu1();
}
}
}
}
while (myTouch.dataAvailable())
; // wait here until they've lifted their finger
}
}
void button(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (x1,y1,x2,y2);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1,y1,x2,y2);
}
// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
//while (myTouch.dataAvailable())
//myTouch.read();
delay(300);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
[/code]