Show Posts
Pages: 1 ... 60 61 [62] 63 64 ... 100
916  Using Arduino / Project Guidance / Re: 4 Digit Seven Segment Display Countdown Timer - Minutes to on: September 09, 2012, 12:23:32 am
Heres a v22 sketch for the " Bollywood Bomb " that I have scratched up from another project of mine.  I havn't tested this version, I dont have time to connect up the switches and display at the moment, but it should basically work, but if you try it we can debug any problems.

You could swap the pin numbers to work on Crossroads allsinging serial board.

For some reason it won't compile without the VirtualWire library , so I left it in.

Connect four pushbuttons to negative for the run pause plus and minus setting buttons.

It drives 4   x  TPIC6B595 serial register/drivers using shiftout,  I have made comments about which pins go to which LED segments.
the " spare" output of the TPIC for minutes units connects to the two dots between the mins and secs, which stays on while counting down, and flashes when paused ( you could swap it round if you ant the opposite effect.)
I have put in a " bombPin " output that you could drive an LED to light for 2 seconds ( or a sounderwhatever ) when countdown reaches zero.

Code:


// Boffin1's  countdown " bomb " timer with preset up down run and pause
//   connect dots  to spare TPIC output on minute units chip, on when counting down, flash when paused
#include <VirtualWire.h>
#define latchPin 19  // rck
#define clockPin 18  // sck
#define dataPin 16   // ser in

int tile [4];
//  bitmap for which leds segements ( TPIC pins ) are lit for numbers 0 - 9, first bit for dots
// this pattern will depend on how the segments are wired up
//       this pattern is for  sequence   =   dots,  e,  d,  c,  g,  b,  f,  a
const byte digitTable [10] = {
  B01110111, B00010100, B01101101, B00111101, B00011110, B00111011, B01111011, B00010101, B01111111,B00111111 }
;  

const byte blanked = B00000000;
int dotState;
int pause = HIGH;
int blank = HIGH;
int mintens = 0;
int minunits = 0;
int sectens = 0;
int secunits = 0;
int timeleft = 0;              
unsigned long previousdotMillis = 0;  
unsigned long previousMillis = 0;    
int mintendisp;
int minunitsdisp;
int sectensdisp;
int secunitsdisp;  
int plusPin = 4;
int minusPin = 5;
int runPin = 6;
int pausePin = 7;
int running;
int bombPin = 8;

//******************************************************        
void setup()
{
  Serial.begin(9600);
  blank == HIGH;
  Serial.println("setup");
  pinMode ( latchPin, OUTPUT);
  pinMode ( clockPin, OUTPUT);
  pinMode ( dataPin, OUTPUT);
  pinMode ( plusPin, INPUT);
  digitalWrite(plusPin, HIGH); // set pullups
  pinMode ( minusPin, INPUT);
  digitalWrite(minusPin, HIGH);
  pinMode ( runPin, INPUT);
  digitalWrite (runPin, HIGH);
  pinMode ( pausePin, INPUT);
  digitalWrite(pausePin, HIGH);

  digitalWrite(latchPin, LOW);      // blanking all displays
  for ( int k=0; k<=3; k++ ){
    shiftOut(dataPin, clockPin, LSBFIRST, blank);
    delay (5);
  }
  digitalWrite(latchPin, HIGH);  
  pinMode ( bombPin, INPUT);
  digitalWrite(bombPin, LOW);
}
//********************************************************************
void loop ()
{  

  checktime();

  if ( mintens + minunits + sectens + secunits  >= 1 ){
    timeleft = HIGH;
  }    // check again after countdown
  else
  {
    timeleft = LOW ;
    pause = HIGH;  
  }     //  flashing dots
  unsigned long currentdotMillis = millis();
  if(currentdotMillis - previousdotMillis > 500) {
    previousdotMillis = currentdotMillis;    
    if (dotState == LOW)
    {
      dotState = HIGH;
    }    
    else     {
      dotState = LOW;
    }  
    showtime ();
  }
  if ( pause == LOW ) {
    dotState = HIGH ;
  }

  

  checkbutton ();    


}//  end of loop


void checktime () {
  if ( mintens + minunits + sectens + secunits  >= 1 )  //  if time still left on countdown
  {
    timeleft = HIGH;
  }
  else {
    timeleft = LOW ;
    pause = HIGH;
  }

  if (timeleft == HIGH ) {
    if ( pause == LOW ) {  //  which means its counting down   i.e. not paused in countdown          
      static unsigned long previousMillis;
      if(millis() > previousMillis)
      {
        previousMillis = millis() + 1000;
        secunits -- ;             // countdown 1 sec
        if ( secunits  < 0 ){
          secunits = 9;  
          sectens -- ;
        }
        if ( sectens   < 0 ){
          sectens = 5;  
          minunits -- ;
        }
        if ( minunits  < 0 ){
          minunits = 9;  
          mintens -- ;
        }
        // mintens cant get to -1 or it would have to have been 0000 and paused
        Serial.print(mintens);  
        Serial.print(minunits);  
        Serial.print(" : ");
        Serial.print(sectens);  
        Serial.println(secunits);
        showtime ();

        if ( mintens + minunits + sectens + secunits  >= 1 ){
          timeleft = HIGH;
        }
        else {
          digitalWrite( bombPin, HIGH ) ;
          timeleft = LOW ;
          pause = HIGH ;
                // milliseconds bombPin goes high
          delay ( 2000 );
        }
        digitalWrite( bombPin, LOW );

      }
      dotState = HIGH;
    } // keeps dots on while countdown
    else
      if ( blank == LOW ) {
      flashdots ();
    }

  }
} // END OF CHECKTIME

void checkbutton ()
{  
  int plus = digitalRead( plusPin );
  if ( plus == LOW ) {    
    secunits ++;  
  }  

  if ( secunits > 9 ){      
    secunits = 0 ;      
    sectens ++;    
  }
  if ( sectens >5 ) {      
    sectens = 0;      
    minunits ++;    
  }
  if ( minunits > 9 ){      
    minunits=0;      
    mintens ++;    
  }
  if ( mintens >5 ){      
    mintens = 0 ;    
  }  

  int minus = digitalRead( minusPin );
  if ( minus == LOW ) {  
    secunits --;
  }

  if ( secunits  < 0 ){      
    secunits = 9;        
    sectens -- ;    
  }
  if ( sectens   < 0 ){      
    sectens = 5;      
    minunits -- ;    
  }
  if ( minunits  < 0 ){      
    minunits = 9;        
    mintens -- ;    
  }  
  if ( mintens < 0 ){        
    mintens =5 ;    
  }

  //  CHANGE THIS DELAY TO SET COUNTSPEED WHEN + or - BUTTON HELD IN
  if ( plus || minus == LOW ){  
    delay ( 100 ) ;    
    showtime ();      
  }  


  // when run button pressed release pause
  int runbutton = digitalRead( runPin );
  if ( runbutton == LOW ) {
    pause = LOW ;
  }


  // when pause button pressed  set pause
  int pausebutton  = digitalRead( pausePin );  
  if ( pausebutton == LOW ) {
    pause = HIGH ;
  }



}  // end of checkbutton function

void flashdots () {
  unsigned long currentdotMillis = millis();
  if(currentdotMillis - previousdotMillis > 500) {
    previousdotMillis = currentdotMillis;    
    if (dotState == LOW)
    {
      dotState = HIGH;
    }
    else  {
      dotState = LOW;
    }    
    showtime ();  
  }
  if ( pause == LOW ) {
    dotState = HIGH ;
  }  
} //  end of flashdots routins

void showtime ()   //  DISPLAY ROUTINE
{  
  int mintendisp = (mintens) ? digitTable [ mintens ] : 0;  //  zero blanking tens minutes
  int minunitsdisp = digitTable [ minunits ];
  int sectensdisp = digitTable [ sectens ];
  int secunitsdisp = digitTable [ secunits ];
  if ( dotState == HIGH ){

    minunitsdisp = minunitsdisp|10000000 ;
  }      //   adds msb to minunit to light dots when dotState high

  digitalWrite(latchPin, LOW);

  shiftOut(dataPin, clockPin, LSBFIRST, mintendisp);
  shiftOut(dataPin, clockPin, LSBFIRST, minunitsdisp);
  shiftOut(dataPin, clockPin, LSBFIRST, sectensdisp);
  shiftOut(dataPin, clockPin, LSBFIRST, secunitsdisp);

  digitalWrite(latchPin, HIGH);
}


917  Using Arduino / Project Guidance / Re: 4 Digit Seven Segment Display Countdown Timer - Minutes to on: September 08, 2012, 05:23:28 am
Sorry Crossroads,

I didnt see the pic of your one, its a lot more versatile than my simple one !    I will probably buy some boards from you next time ( I have just ordered another load of mine )

918  Using Arduino / Project Guidance / Re: 4 Digit Seven Segment Display Countdown Timer - Minutes to on: September 08, 2012, 01:03:16 am
I made up a little pcb  that I use for 7 seg displays, it is stand alone ( program the 328 on your arduino, then plug it in the board)
I have put some 10 pin idc headers on it, 4 for the first 4 digits ( as in a clock ), and one on the right of the board to carry on to more numbers if needed ( each digit has a TPIC6B595  high power latch driver that can drive massive digits )
The headers have 7 pins for segments a-g, and 3 pins for the LED supply.

There is another header on the left for gen purpose I/O to some of the pins of the micro. I use these for connecting to wireless / push buttons/ GPS / whatever.

There is also provision for a couple of power fets for switching other LEDs, horn , motor etc.

The board has its own 5v regulator, I generally supply 12v ( depending on the number of LEDs in series for each segment )



I can post the gerber files if anyone wants to make these, or I could perhaps supply the boards if anyone is interested.

I have a  a simple sketch for the countdown bomb, with a couple of push buttons to preset the start time, and a run/pause button.

919  Using Arduino / Storage / Re: power down data saving on: September 07, 2012, 06:25:45 pm
While the power is coming in to the regulator, the zener feeds a voltage to the base of the transistor, which switches on, keeping the DCgone pin low.

The normal loop keeps running while the DCgone pin is low, but when the incoming voltage drops below about 8 volts, the transistor switches off, but the 470mF capacitor is still charged ( the diode stops the power supply discharging the  470mF cap )and supplies 5 volts to the chip for about half a second.

On the next loop, the DCgone pin is high, and the variables are saved to the eeprom in the chip.

The unsaved flag only allows it to save the data once, as you dont want it to keep saving every loop as the 5 volt fades away.

When the power comes on again, the saved variables are read from the eeprom during setup.
920  Community / Bar Sport / Re: As people seem to occasionally mention things like this.. on: September 07, 2012, 02:26:42 am
Congratulations  - 
921  Development / Suggestions for the Arduino Project / Re: Interest in overhauling the IDE user interface? on: September 06, 2012, 03:36:11 pm
Thats a relief that it wasnt just me imagining the custard screen :-)
922  Development / Suggestions for the Arduino Project / Re: Interest in overhauling the IDE user interface? on: September 06, 2012, 12:27:43 pm
Yes, it my be my slow reactons, but ofen I end up with a whole yellow page...
923  Development / Suggestions for the Arduino Project / Re: Interest in overhauling the IDE user interface? on: September 06, 2012, 11:24:12 am
when you try and select just a line or two of text, and suddenly you get a load of yellow lines selected -  perhaps its one of my settings ?
924  Community / Bar Sport / Re: So why are there no good electronics shops? on: September 06, 2012, 10:44:21 am
Quote
it was moved out to a more major road because it's original location was too far off the tourist track.

That takes away a bit of authenticity perhaps ( for those who dont recognise Walkabout Creek and its pub - it was in the movie Crocodile Dundee )

So the massive road train trucks going by was a bit far fetched then :-)

Glad you didnt have the recession, or perhaps your life style made you miss it !
925  Community / Bar Sport / Re: So why are there no good electronics shops? on: September 06, 2012, 09:12:37 am
Didn't hit Walkabout Creek then Rob ?
926  Community / Bar Sport / Re: I think I give up :) on: September 06, 2012, 05:01:35 am
 I dont understand half the spec, or I might give up too.

Luckily my niche (  LED scoreboards ) have to be read from 150m away, so hopefully they dont bring out a giant 4 sq m version :-)
927  Community / Bar Sport / Re: So why are there no good electronics shops? on: September 06, 2012, 04:54:21 am
Yes,  you just cant get good service since the recession :-)
928  Community / Bar Sport / Re: So why are there no good electronics shops? on: September 06, 2012, 03:58:46 am
10 years back we lived in a tiny village at the southernmost tip of Africa ( L'Agulhas )  at the end of a dead end road ,  260 kM from the nearest city ( Cape Town ) , and 86 kM from the nearest main road.

RS Components had an arrangement with a courier company  for delivery anywhere in South Africa at a fixed price, and one day I ordered a small plastic bush for something - 2 bucks worth I think -  and a few days later the courier van pulled up to deliver the little envelope.
Thats about a five hour round trip.

I dont know if they still do this, but I see RS have closed down there shop in Cape Town !
929  Using Arduino / Storage / power down data saving on: September 05, 2012, 01:09:03 pm
I did see a few posts a while ago about saving variables to eeprom when the power goes down, but I didnt see actual circuits or sketch.

I am using this ciruit ( schematic ) on my embedded projects, any suggestions for improvements welcome.  It works for brown outs too.



The digital transistor monitors when the DC input drops below about 8 volts ( you can reduce the zener voltage if using a lower input voltage )

The 470 mFD cap supplies enough power to write to eeprom when the power goes ( or drops low )

The collector is connected to a pin on the ATmega - which should be set for an input with pull-up.

Code:
#include <EEPROM.h>
int DCgone = 5;
 int unsaved= HIGH;
int DCgoneState= LOW;


then include in void () setup ;

 XH = EEPROM.read (1);     //  XH etc are the variables we stored at brown out/power down last time
 XT = EEPROM.read (2);
 XU = EEPROM.read (3);
 XC = EEPROM.read (4);
 NH = EEPROM.read (5);
 NT = EEPROM.read (6);
 NU = EEPROM.read (7);
 NC = EEPROM.read (8 ) ;

pinMode ( DCgone, INPUT );
digitalWrite(DCgone, HIGH);  // sets pullup resistor


  void loop()
  {
  DCgoneState = digitalRead ( DCgone );  
   if ( DCgoneState == LOW )
                          {  

  *************   Run your loop here   *************     }
  else {  
 if ( unsaved == HIGH  )  {   //   we only want to save to eeprom once when power fails
    writeeeprom ();
    unsaved = LOW;    
 }
  }
 } //end of loop

void writeeeprom () {
    EEPROM.write(1,XH);
    EEPROM.write(2,XT);
    EEPROM.write(3,XU);
    EEPROM.write(4,XC);
    EEPROM.write(5,NH);
    EEPROM.write(6,NT);
    EEPROM.write(7,NU);
    EEPROM.write(8,NC);
}
  




930  Development / Suggestions for the Arduino Project / Re: Interest in overhauling the IDE user interface? on: September 05, 2012, 11:52:21 am
What bugs me is the  "Screen of Custard "  when trying to select a couple of lines of text  :-(

Perhaps my mouse control isnt as good as it was :-)
Pages: 1 ... 60 61 [62] 63 64 ... 100