Show Posts
Pages: 1 ... 77 78 [79] 80 81 ... 100
1171  Using Arduino / LEDs and Multiplexing / dead key on keypad library ? on: June 30, 2011, 02:45:18 pm

I started posting about a problem I had with KeyPad, where one key was not working, but just typing it up gave me the clue, so I will just mention it in case others have the same problem.

The unit is a remote control, using VirtualWire driving the transmitter.  I reallocated the default transmit pins ( data and PTT ) to 15 and 13 to suit my layout.

Being only a transmitter I completely forgot that VirtualWire also allocates pin 11 as the default vw_set_rx_pin, which I had as set as one of the columns in KeyPad.

Reallocating the vw_set_rx_pin to a spare pin cured it of course.
1172  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library on: June 29, 2011, 02:49:41 am


Good tips, I will try them
1173  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library on: June 29, 2011, 12:43:39 am
Right, but actually, would it not be possible for the compiler to spot that particular error quite easily?  and say " that ain't gonna get to 3 to start counting"

Or if you have the perennial   if ( a=0 )  instead of a==0  ,    it could nudged you and say "are you sure you want to make a be zero right now?"

Or perhaps us old farts should pay more attention to what we are typing, but I get carried away when I can see the code in my head, and just want to test it.
1174  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library sorted ! on: June 28, 2011, 03:57:13 pm

Its working now,  some idiot typed   for ( int n =0; n>=3; n++ )   instead of  for ( int n =0; n<=3; n++ )   smiley-eek-blue

1175  Using Arduino / Programming Questions / Re: what is permitted in a switch case? on: June 28, 2011, 03:53:22 pm


You wont believe how many times I overlooked that while going through for ==  etc !

It now works of course....  what a great forum !
1176  Using Arduino / Programming Questions / Re: what is permitted in a switch case? on: June 28, 2011, 03:39:26 pm
LOL  -   I really can't believe I did that !!    smiley-red

Thanks a lot
1177  Using Arduino / Programming Questions / what is permitted in a switch case? on: June 28, 2011, 02:55:38 pm
  Is it OK to run functions and for () functions inside various cases of a switch structure ?

These functions  redtens ();  zero();  and   one();   all run OK on their own, but the code just doesn't run the switch statement....  heres a bit of the code:-


Code:
break;
      case 2:
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redtens ();  //  sends tile and customer number for red tens
          zero();
          one();
          zero();
          zero();       
          digitalWrite(dataPin, LOW );

        break;
      case 3:
1178  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library on: June 28, 2011, 04:25:36 am

second half with some snipped:-

Code:

     //////////////////////////////////////////////////////////////////////////////
      }
   
      switch (counter1)  {      // for counter2 = Red tens
      case 0:
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redtens ();  //  sends tile and customer number for red tens
          zero();
          zero();
          zero();
          zero();  //  BCD for 0,  pins 10( LSB)-13 ,  D0-D3
          digitalWrite(dataPin, LOW );   
        }
        //////////////////////////////////////////////////////////////////////////////
        break;
      case 1:
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redtens ();  //  sends tile and customer number for red tens     
          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++ ){
          redtens ();  //  sends tile and customer number for red tens
          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++ ){
          redtens ();  //  sends tile and customer number for red tens
          zero();
          one();
          zero();
          zero();  //  BCD for 0,  pins 10( LSB)-13 ,  D0-D3
          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++ ){
          redtens ();  //  sends tile and customer number for red tens
          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++ ){
          redtens ();  //  sends tile and customer number for red tens
          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++ ){
          redtens ();  //  sends tile and customer number for red tens
          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++ ){
          redtens ();  //  sends tile and customer number for red tens
          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++ ){
          redtens ();  //  sends tile and customer number for red tens
          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++ ){
          redtens ();  //  sends tile and customer number for red tens
          one();
          zero();
          zero();
          one();  //  BCD for 9,  pins 10( LSB)-13 ,  D0-D3
          digitalWrite(dataPin, LOW );           
        }
        break;
   //  SOME CODE CHOPPED HERE TO SAVE SPACE POSTING

      }

    //***********************************************************************************
  }  //  if ( vtstate == HIGH )
}   // end loop



void one ()
{
  digitalWrite(dataPin, LOW);
  delayMicroseconds(210);
  digitalWrite(dataPin, HIGH);
  delayMicroseconds(105);
}
void zero () {
  digitalWrite(dataPin, LOW);
  delayMicroseconds(105);
  digitalWrite(dataPin, HIGH);
  delayMicroseconds(210);
}
void redhundreds () {   //  sends tile and customer number for red hundreds
  digitalWrite(dataPin, LOW );
  delay (4);
  one (); //  sync bit

  zero();
  one ();
  zero();
  one ();  // pins 1-4 add 0-3 tile number = red hundreds

  zero();
  one ();
  one();
  one ();   //  customer number 0111 pins 5678  A4-A8
}

void redtens () {   //  sends tile and customer number for red tens
  digitalWrite(dataPin, LOW );
  delay (4);
  one (); //  sync bit

  one();
  one ();
  one();
  zero ();  // pins 1-4 add 0-3 tile number = red tens

  zero();
  one ();
  one();
  one ();   //  customer number 0111 pins 5678  A4-A8
}

void redunits () {   //  sends tile and customer number for red units
  digitalWrite(dataPin, LOW );
  delay (4);
  one (); //  sync bit

  zero();
  zero ();
  one();
  zero ();  // pins 1-4 add 0-3 tile number = red units

  zero();
  one ();
  one();
  one ();   //  customer number 0111 pins 5678  A4-A8

}


}

1179  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library on: June 28, 2011, 04:21:20 am
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?
Code:

//    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]
1180  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library on: June 27, 2011, 01:20:55 pm
Thanks Rob,

I will have a look at these,

It looks like delay Micros will be fine for the data, and normal delay for the gaps I guess.
1181  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library - new slant on it on: June 27, 2011, 12:15:13 pm
Some years ago  - BIFA - ( before I found Arduino  ),  I made a display board with 9 LED displays, each with it's own HT12D decoder , a CD4011  BCD-7 seg decoder, and ULN2003 driver.

The board has 3 sets of 3 digit numbers 0-999 , each set a different colour .  The original unit had a single remote control, with 3 sets of BCD switches.
 
I have to change the transmitting end, but don't really want to rebuild the whole display, which is working fine.

I have to have 3 separate remotes, each with a single button that increments its own colour counter with each press.
If the button is held in the counter is reset to zero ( I think this request is impractical, it would be better to have the units reset first, then the tens, then the thousands, or it could take forever to correct a mistake )

I have 3 spare transmitter units with HT12E encoder chips and transmitters, so each can send a simple code to the receiver, which I can try the HT12 library again, or use a HT12D chip ( I couldn't get the library going last time )

I am thinking of taking the BCD data ( representing button 1, 2 , or 3 ) from the decoder chip, and feeding this to an Atmega chip.  ( or even easier if the library for the decoder works for me )

I can do a bit of manipulation with the counting and the reset timing, but then I want to send out the Holtek protocol data to the 9 chips, with the correct address code for the one that needs changing.

I think I can do it, but I just need some advice on generating the pulse widths of the ones, zeros, and spaces.

Is the micros or  millis accurate enough?   or is there another preferred method ?
1182  Using Arduino / Programming Questions / Re: Arduino crashes after 15-20 hours or running on: June 17, 2011, 10:10:29 am
Hopefully my code for these projects will be as good as it gets now,  it has been working in 4 other projects with no trouble as it was, warts and all, but with decent power supplies.

Its all a learning curve, for instance it was only when I looked at a photo I took to post here of the UUT running, that I saw my celphone on charge 200mm away,  I have been caught out with that before !

This unit will be fitted to a scoreboard on the far side of a field, so I don't have to worry about any interference from garage openers or celphones, but I couldn't take a chance.  This should have gone out last week....

By next week I should be working on one project at a time,   ---    bliss
1183  Using Arduino / Programming Questions / Re: Arduino crashes after 15-20 hours or running on: June 17, 2011, 03:35:22 am

I think my problem must have been a noisy power supply !  ( I was using a JUS mains adaptor that the supermarkets sell )

Its been working 20 hours OK now since I changed the PSU   (and made the loop wait for a new message wit the blocking VirtualWire wait instruction.)

Good luck with yours
1184  Using Arduino / Programming Questions / Re: Project freezes after several hours on: June 17, 2011, 03:33:23 am

I think it must have been a noisy power supply !

Its been working 20 hours OK now since I changed the PSU   (and made the loop wait for a new message wit the blocking VirtualWire wait instruction.)

Thanks for the forums help
1185  Using Arduino / Programming Questions / Re: Arduino crashes after 15-20 hours or running on: June 16, 2011, 02:28:41 pm
@Greg

Is your problem unit an arduino board powered by the usb?
Pages: 1 ... 77 78 [79] 80 81 ... 100