Rechecking input after a few seconds

Hello everyone,
I am trying to climb the steep learning curve of programming.
I am trying to use a nano to control
mc145155TESTscanlcd.ino (20.3 KB)
a scanning receiver. PLL and scan functions.
I have a few issues but I will address just one for this post.

while(digitalRead(12)==1) ; //during signal detected, wait. //at this point when the signal (pin 12) //goes low, I want to wait a few seconds, recheck pin 12 and if it is high again, redo the while loop. //keep doing this until the signal is low after the few second delay.
++sum; //increment scan
if(sum > 46) //reset channel to 1
{
sum = 1; //sum is used by switch ... case to select channels
}

Those who are familiar with radio scanners may be familiar with what i am trying to do. presently as soon as the signal is lost it continues scanning channels.
Thank you
Michael

Please read the forum instructions to understand how to post your code so it can be examined.

#include <Rotary.h>
Rotary r = Rotary(A0, A1);


#include <LiquidCrystal.h>
const int rs = 7, en = 8, d4 = 3, d5 = 4, d6 = 5, d7 = 6;  //set up lcd pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


int sig = 12;  //squelch input
int clk = 9;   //pll programming pins
int dat = 10;  //pll programming pins
int ena = 11;  //pll programming pins
//int led = 13;
int sum = 1;   //scan channel 
int encoder = 0;   //rotary encoder status
 
 void setup() {
pinMode(sig, INPUT_PULLUP);
pinMode(clk, OUTPUT);
pinMode(dat, OUTPUT);
pinMode(ena, OUTPUT);
//pinMode(led, OUTPUT);
digitalWrite(clk, LOW);
digitalWrite(dat, LOW);
digitalWrite(ena, LOW);
//Serial.begin(9600);
}

void loop() {
  lcd.clear();  
//lcd.print("    ");
  
switch (sum) {      //which channels to scan
  case 1:
    five110();
    //lcd.print("   ");
    lcd.print("145.110Mhz");
    break;
  case 2:
    five170();
   // lcd.print("   ");
    lcd.print("145.170Mhz");
    break;
  case 3:
    five210();
   // lcd.print("   ");
    lcd.print("145.210Mhz");
    break;
  case 4:
    five230();
    //lcd.print("   ");
    lcd.print("145.230Mhz");
    break;
  
    
  default:
    seven015(); 
    lcd.print("147.015Mhz");  
    // if nothing else matches, do the default
    // default is optional
    break;
   }

enabl();                    // go to Enable pulse
 
 }
   
// zero:  load 0 bit
void z(){
digitalWrite(dat,LOW);     // Load 0 on dat
digitalWrite(clk,HIGH);    // bring clock HIGH
digitalWrite(clk,LOW);     // Then back low
}
// one:  load 1 bit
void o(){
digitalWrite(dat,HIGH);    // Load 1 on DAT
digitalWrite(clk,HIGH);    // Bring pin CLOCK high
digitalWrite(clk,LOW);     // Then back low
}
void enabl(){
digitalWrite(ena, HIGH);   // Bring Enable high
digitalWrite(ena, LOW);    // Then back low
delay(100);
while(digitalRead(12)==1) ; //during signal detected, wait.
++sum;                      //increment scan
if(sum > 46)                //reset channel to 1
  {
  sum = 1;
  }
  delay (100);
}



// programmed channels
void five110(){  
z();         // 8192
z();         // 4096

o();         // 2048
o();         // 1024
z();         // 512
z();         // 256

z();         // 128
o();         // 64
o();         // 32
o();         // 16

o();         // 8
z();         // 4
o();         // 2
o();         // 1
}

void five170(){  
z();         // 8192
z();         // 4096

o();         // 2048
o();         // 1024
z();         // 512
z();         // 256

o();         // 128
z();         // 64
z();         // 32
z();         // 16

z();         // 8
o();         // 4
o();         // 2
o();         // 1
}

void five210(){ 
z();         // 8192
z();         // 4096

o();         // 2048
o();         // 1024
z();         // 512
z();         // 256

o();         // 128
z();         // 64
z();         // 32
z();         // 16

o();         // 8
o();         // 4
o();         // 2
o();         // 1
}

void five230(){
z();         // 8192
z();         // 4096

o();         // 2048
o();         // 1024
z();         // 512
z();         // 256

o();         // 128
z();         // 64
z();         // 32
o();         // 16

z();         // 8
z();         // 4
o();         // 2
o();         // 1
}



void seven015(){ 
z();         // 8192
z();         // 4096

o();         // 2048
o();         // 1024
z();         // 512
o();         // 256

o();         // 128
o();         // 64
o();         // 32
o();         // 16

o();         // 8
z();         // 4
z();         // 2
z();         // 1
}

goes low, I want to wait a few seconds, recheck pin 12 and if it is high again, redo the while loop.

Try something like this:

do {
if (digitalRead(12) == LOW) delay(a_few_seconds*1000UL);
} while(digitalRead(12)==HIGH) ; //during signal detected, wait.

Thank you, I'll give it a shot.
I do need to understand the
delay(a_few_seconds*1000UL);
part .
A variable times 1 second? not sure what the "UL" means.
yes, I am very much a newbie.

This seems to delay every channel, I want the delay only on a previously active channel.

UL forces the result of the multiplication of your seconds times 1000 milliseconds into an unsigned long variable. Also needed because default unsigned int will overflow at about 32+ seconds.
Leo..

That requires more complicated logic. I suggest to use a "flag variable" (look it up). Give it a try, and if you run into trouble post again.

I gave up and used a hardware solution with a 74ls123
I can handle hardware fine, but this software makes my eyes bleed.
It's like trying to understand an alien language.

It is an alien language, and people argue endlessly over the meaning of the words.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.