HT12E library

Well I hooked together some switches and set some pullups, and have a sort of code, with odd serialprint telltales here and there, it runs until it gets to the "switch" function, I put a serialprint there and it doesnt show up.

The idea is that 3 remotes can each increment their own coloured display with a pushbutton, which comes to the chip via a HT12 decoder as Bin0 Bin1 and Bin2, and the valid transmission VT from the HT12.

I need to be able to reset each counter by holding the button in, so I included a flag to stop it incrementing each loop while the buttons pressed. I am not using a real timer for the reset delay, just counting loops.

heres the code for as far as the red button, the monitor shows it gets to serial print counter 2, but not the switch function, can I use functions() as I have here, being called from other functions? or perhaps I cannot have for loops in a switch case ? any ideas?

//    June 18  queue display testing for driving existing HT12s

int timeout =1000;  // set timing counter for resetting with vt  ---- testing very long !
int  vtPin = 15;
int   bin2Pin = 17;
int   bin1Pin = 18;
int   bin0Pin = 19;

int dataPin = 9;
int  vtimer =0;
int counter0=0;
int counter1=0;
int counter2=0;
int counter3=0;
int counter4=0;
int counter5=0;
int counter6=0;
int counter7=0;
int counter8=0;
int bin0=0;
int bin1=0;
int bin2=0;
int countflag=0;

void setup(){ 

  pinMode(dataPin, OUTPUT);
  pinMode (vtPin, INPUT);
  digitalWrite(vtPin, HIGH ); // pull up needed only for testing
  pinMode (bin2Pin, INPUT); 
  digitalWrite(bin2Pin, HIGH ); 
  pinMode (bin1Pin, INPUT); 
  digitalWrite(bin1Pin, HIGH ); 
  pinMode (bin0Pin, INPUT); 
  digitalWrite(bin0Pin, HIGH ); 

  Serial.begin(9600); 
}
void loop(){  
  int vtstate = !digitalRead(vtPin); // valid transmission from decoder     //   REMOVE NOT AFTER TESTING
  int bin2 = !digitalRead(bin2Pin);
  int bin1 = !digitalRead(bin1Pin);
  int bin0 = !digitalRead(bin0Pin);
  //*************************************************************************************
  if ( vtstate == LOW ) { 
    vtimer = 0 ; 
    countflag = LOW;     
  }


  if ( vtstate == HIGH ) {             // the whole part  of the loop below here only actions while VT is high         
    //   increment the reset counter
    vtimer ++;

    Serial.print("vtimer ==  ");
    Serial.println (vtimer);
    ////////////////////////////////////////////////////////////////////////////////////////

    //   FOR LEFT HAND DISPLAY  counter 0 hundreds ,1 tens , and 2 units   Red LEDs

    //   if  RED remote  button  pressed =  bin0 from HT12 on receiver, 3 red digits count to 999 ( counter 0,1,2 )
    if ( bin0 == HIGH ) {  

      Serial.print("bin0 ==  ");  
      Serial.println (bin0);  // testing

      // if vt button greater than timeout, rest bin0 3digits and vtimer
      if ( vtimer >= timeout ) { 
        vtimer = 0 ; 
        counter0 = 0; 
        counter1=0;  
        counter2=0; 
      }
      // only increment counter once per button push so it doesnt count on loop while resetting

      Serial.print("countflag==  ");
      Serial.println (countflag);

      if (countflag == LOW ) {  
        counter2 ++; 
        if ( counter2 >= 10) { 
          counter2 = 0;
          counter1  ++;
        }     
        if ( counter1 >= 10) { 
          counter1 = 0;
          counter0  ++;
        }
        if ( counter0 >= 10) { 
          counter0 = 0;
        }               

        countflag = HIGH;   // inhibit counting until vt has been low again
      }
      
     
      Serial.print("counter2 ==  ");  
      Serial.println (counter2);
     
      ///////////////////////////////////   Generate bcd data for these 3 RED numbers and send 4 times
      
         switch (counter2)  {      // for counter2 = Red units 
      case 0:
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redunits ();  //  sends tile and customer number for red units
          zero(); 
          zero(); 
          zero(); 
          zero();  //  BCD for 0,  pins 10( LSB)-13 ,  D0-D3
          digitalWrite(dataPin, LOW );           
 
          Serial.print("got to counter 2 red units switch function==  ");  //****************************testing
          Serial.println (n);         
          
        }
        //////////////////////////////////////////////////////////////////////////////
        break;
      case 1:
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redunits ();  //  sends tile and customer number for red units      
          one(); 
          zero(); 
          zero(); 
          zero();  //  BCD for 1,  pins 10( LSB)-13 ,  D0-D3       
          digitalWrite(dataPin, LOW );

        }
        //////////////////////////////////////////////////////////////////////////////
        break;
      case 2:
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redunits ();  //  sends tile and customer number for red units
          zero(); 
          one(); 
          zero(); 
          zero();  //  BCD for 2,  pins 10( LSB)-13 ,  D0-D3       
          digitalWrite(dataPin, LOW );
       

        }
        //////////////////////////////////////////////////////////////////////////////

        break;
      case 3:
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redunits ();  //  sends tile and customer number for red units
          one(); 
          one(); 
          zero(); 
          zero();  //  BCD for 3,  pins 10( LSB)-13 ,  D0-D3
          digitalWrite(dataPin, LOW );           
        }
        //////////////////////////////////////////////////////////////////////////////
        break;      
      case 4 :
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redunits ();  //  sends tile and customer number for red units
          zero(); 
          zero(); 
          one(); 
          zero();  //  BCD for 4,  pins 10( LSB)-13 ,  D0-D3
          digitalWrite(dataPin, LOW );            
        }
        ////////////////////////////////////////////////////////////////////////////// 
        break;
      case 5 :
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redunits ();  //  sends tile and customer number for red units
          one(); 
          zero(); 
          one(); 
          zero();  //  BCD for 5,  pins 10( LSB)-13 ,  D0-D3
          digitalWrite(dataPin, LOW );            
        }
        ////////////////////////////////////////////////////////////////////////////// 
        break;
      case 6 :
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redunits ();  //  sends tile and customer number for red units
          zero(); 
          one(); 
          one(); 
          zero();  //  BCD for 6,  pins 10( LSB)-13 ,  D0-D3
          digitalWrite(dataPin, LOW );            
        }
        ////////////////////////////////////////////////////////////////////////////// 
        break;
      case 7 :
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redunits ();  //  sends tile and customer number for red units
          one(); 
          one(); 
          one(); 
          zero();  //  BCD for 7,  pins 10( LSB)-13 ,  D0-D3
          digitalWrite(dataPin, LOW );            
        }
        ////////////////////////////////////////////////////////////////////////////// 
        break;
      case 8 :
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redunits ();  //  sends tile and customer number for red units
          zero(); 
          zero(); 
          zero(); 
          one();  //  BCD for 8,  pins 10( LSB)-13 ,  D0-D3
          digitalWrite(dataPin, LOW );            
        }
        ////////////////////////////////////////////////////////////////////////////// 
        break;
      case 9 :
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redunits ();  //  sends tile and customer number for red units
          one(); 
          zero(); 
          zero(); 
          one();  //  BCD for 9,  pins 10( LSB)-13 ,  D0-D3
          digitalWrite(dataPin, LOW );            
        }
        
        break;
  [code]
continued next message

[/code]