Hi.
My problem.
I need to break a loop / goto on the press of a button.
At the moment i have the circuit working as it is should do, when i press button1 the program jumps to the next function stores it in memory and displays what it is supposed to do. On button2 i have it going to a function that displays all the functions every 15 secs, but as you can see from my code once i put it into a loop i cannot get out of it. I would like button2 to either switch the loop on or off depending on the current state of the loop.
Has anyone have any ideas on a better way approach this, at the moment the only i can break the loop is by doing a reset but i would like it to work only the buttons alone.
look at the function displayall() this is where my problem is.
Thanks.
#include <TVout.h>
#include <fontALL.h>
#include <EEPROM.h>
TVout TV;
const int pushButton = 2;
const int pushButton1 = 3;
int buttonState;
int buttonState1;
int led = 13;
int epromvalue;
int epromaddress = 1;
int buttonPushCounter;
long randNumber;
int totalfunctions = 4;
void setup() {
pinMode(pushButton, INPUT);
pinMode(pushButton1, INPUT);
pinMode(led, OUTPUT);
TV.begin(PAL,120,96);
TV.select_font(font6x8);
epromvalue = EEPROM.read(epromaddress);
switch (epromvalue)
{
case 1:
TV.clear_screen();
block1();
break;
case 2:
TV.clear_screen();
block2();
break;
case 3:
TV.clear_screen();
block3();
break;
case 4:
TV.clear_screen();
block4();
break;
}
randomSeed(analogRead(0)); //?
}
void loop() {
buttonState = digitalRead(pushButton);
buttonState1 = digitalRead(pushButton1);
if (buttonState1 == HIGH)
{
displayall();
TV.clear_screen();
}
if (buttonState == HIGH)
{
digitalWrite(led, HIGH);
buttonPushCounter++;
if (buttonPushCounter > totalfunctions)
{
buttonPushCounter = 1;
}
TV.clear_screen(); //Only do a clear screen if the button is pressed.
switch (buttonPushCounter)
{
case 1:
block1();
break;
case 2:
block2();
break;
case 3:
block3();
break;
case 4:
block4();
break;
}
}
else
{
digitalWrite(led, LOW);
}
delay(1000);
}
void displayall()
{
here:
digitalWrite(led, HIGH);
loadbars();
block1();
TV.delay(14000);
loadbars();
block2();
TV.delay(14000);
loadbars();
block3();
TV.delay(14000);
loadbars();
block4();
TV.delay(14000);
digitalWrite(led, LOW);
goto here;
}
void block1()
{
TV.draw_rect(0,0,TV.hres()-1,TV.vres()-10,WHITE,WHITE);
TV.print(0,88,"2E0AVI - 144.750");
EEPROM.write(epromaddress, 1);
}
void loadbars()
{
//draw_rect(x0,y0,width,height,color,fillcolor)
//TV.draw_rect(0,0,1,10,WHITE,WHITE);
TV.clear_screen();
TV.select_font(font6x8);
TV.draw_rect(18,28,80,34,WHITE);
TV.print(38,75,"LOADING");
for (int i=20; i<95;i++)
{
//TV.println(i);
TV.draw_rect(i,30,1,30,WHITE,WHITE);
randNumber = random(0, 110);
delay(randNumber);
}
TV.clear_screen();
//TV.draw_column(5,5,60,WHITE);
// TV.draw_row(1,0,60,WHITE);
}
void block2()
{
TV.clear_screen();
TV.select_font(font6x8);
TV.draw_rect(18,28,80,34,WHITE);
TV.print(37,40,"2E0AVI");
EEPROM.write(epromaddress, 2);
}
void block3()
{
TV.select_font(font6x8);
TV.draw_rect(0,0,TV.hres()-1,TV.vres()-3,WHITE);
TV.draw_rect(0,0,TV.hres()-1,12,WHITE);
TV.print(39,3,"GENERATOR");
TV.draw_rect(0,12,TV.hres()-1,10,WHITE);
TV.print(2,14,"CALLSIGN : 2E0AVI");
TV.draw_rect(0,22,TV.hres()-1,10,WHITE);
TV.print(2,24,"TALKBACK : 144.750");
TV.draw_rect(0,42,TV.hres()-1,10,WHITE);
TV.print(2,34,"NAME : ANTHONY");
//TV.draw_rect(74,12,40,82,WHITE);
TV.print(2,44,"LOCATION : IO93LE");
TV.draw_rect(0,62,TV.hres()-1,10,WHITE);
TV.print(2,54,"V/OUTPUT : 435.000");
TV.print(2,64,"POWER : 2W");
TV.draw_rect(0,82,TV.hres()-1,10,WHITE);
TV.print(2,74,"MODE : AM");
int h = TV.hres();
int v = TV.vres();
TV.print(2,84,"H/V RES :");
TV.print(45,84,h);
TV.print(65,84,"X");
TV.print(72,84,v);
EEPROM.write(epromaddress, 3);
}
void block4()
{
TV.clear_screen();
TV.select_font(font6x8);
TV.print(43,35,"2E0AVI");
TV.draw_row(45,0,118,WHITE);
TV.print(36,50,"70CM ATV");
EEPROM.write(epromaddress, 4);
}