Show Posts
Pages: 1 ... 77 78 [79] 80 81 ... 100
1171  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 !
1172  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
1173  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:
1174  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

}


}

1175  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]
1176  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.
1177  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 ?
1178  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
1179  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
1180  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
1181  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?
1182  Using Arduino / Programming Questions / Re: Project freezes after several hours on: June 16, 2011, 05:34:37 am
Thanks I will have a look at that serial print.


I cant add serial prints for debugging as it only hangs up with the chip plugged into the equipment, if I hook up an arduino board to the same Rx output, it doesnt latch !

Meanwhile I have added        vw_wait_rx()      

which makes it wait for an input (blocking )

I only need the loop to do anything after getting a message ( my displays are latched, not multiplexed )

It takes many hours to test it though !  I ill change that serial thing in setup anywaay.
1183  Using Arduino / Programming Questions / Re: Arduino crashes after 15-20 hours or running on: June 16, 2011, 03:39:05 am
Hi Greg

I have that in my code, unfortunately  smiley-sad

I am using a cheap switch mode power supply, I am going to try another type this morning, and I have even tried moving my celphone away from the unit under test, really clutching at straws now..

I have just noticed that neither of us have the
if (vw_have_message() )   
that codingbadly suggested .  I think I will study the VW pdf again ( RTFM )

I know for instance that I will be receiving 20 bytes every message, so perhaps I can get it to check buflen is 20, but then again  thats what VW is doing when it sends buflen anyway....

As I only need the loop to do anything after getting a message ( my displays are latched, not multiplexed ) I am trying the instruction

vw_wait_rx()

which is blocking, the trouble is I might only know by tonight really if its working ...
1184  Using Arduino / Programming Questions / Re: Project freezes after several hours on: June 16, 2011, 03:07:48 am
OK  I have removed the capacitor, set all the unused inputs to pullups and it still freezes after several hours.

if I hook the receivers data to an arduino board as well, that board doesn't hang, i.e. the data is OK from the rf module.

But I could perhaps get the arduino one to print buflen every time it sees a message ( presumably anything with the right datarate? )

I wonder if this has something to do with it, I don't use multiplexing for my displays, all the LED segments are latched by the TPIC shift regs.

So once the data is displayed, the loop is only checking for a correct length message coming in :-

Code:

void loop ()
{

  //        CHECK FOR INCOMING MESSAGE
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
 
  delay (20);
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {


that's the loop,  I don't now why the delay is in there, I think that was part of the code I copied.

Greg who has a similar problem doesn't have the delay...

I have several units in the field with this same front end ( up until the "got " message,  that are running fine without hanging up )

It was hung up again this morning , so I guess I will try putting a  switch on the RF modules supply, and just power it up when I want to test it.

Except then there would be no constant white noise coming into the chip, which might confuse it,,,,,,,

Or perhaps  I could disconnect the antenna, and wrap the receiver in foil ( test it with the remote to make sure nothing is getting through ) and just fold the foil open to test it every few hours..

Now the plot thickens !   I had left it frozen, and without my rebooting it the displays have changed ( I have only three 7seg displays hooked up for testing ) one is blank, and one has random segments on ( not a number ).  The lookup table has only valid patterns on.

And when I sent an update from the remote, it worked and displayed the right numbers again....

Driving me nuts !
1185  Using Arduino / Programming Questions / Re: Arduino crashes after 15-20 hours or running on: June 15, 2011, 05:07:11 pm
Greg

Its that bl***y great flat topped mountain doing it !!!!

but give me a clue and I can test at the same time ..
Pages: 1 ... 77 78 [79] 80 81 ... 100