Go Down

Topic: Wanted someone to do a little bit of code ££££  (Read 998 times) previous topic - next topic

GregorMac

Hi,
need someone to do some coding help and im willing to pay.

Ive been trying to get this done myself to limited success with the code below displays a 3 min countdown but for some reason I cant get it to start at 3.00 mins- it always starts at 3.09



//Using 2 7-segment displays with the 74HC595 shift registers
//CC by-sa-nc 3.0
//http://tronixstuff.wordpress.com
// */


int minutesTens = 0; // count the minutes tens


int minutesUnits = 3; // count the minutes units


int secondsTens = 0; // count the seconds tens


int secondsUnits = 0; // count the seconds units


// Pin connected to ST_CP (pin 12) of 74HC595
int latchPin = 3;


// Pin connected to SH_CP (pin 11 of 74HC595
int clockPin = 10;


// Pin connected to DS (pin 14) of 74HC595
int dataPin = 12;


// Initialise a two Dimensional integer array with
// the values for 0 - 9 on the Seven Segment LED Display
// and 0-9 with the decimal point!


static byte seven_seg_digits[2][10]= {
                             {
    0x7e, // 0
    0x0c, // 1
    0xb6, // 2
    0x9e, // 3
    0xcc, // 4
    0xda, // 5
    0xfa, // 6
    0x0e, // 7
    0xfe, // 8
    0xce  // 9   
    },
                             {
    0x7e, // 0
    0x0c, // 1
    0xb6, // 2
    0x9e, // 3
    0xcc, // 4
    0xda, // 5
    0xfa, // 6
    0x0e, // 7
    0xfe, // 8
    0xce  // 9   
    }
   
                             };


/*
   
  without decimal point
  { 1,0,1,1,1,1,0,1 },  // = 189 in decimal
  { 1,0,0,0,0,1,0,0 },  // = 132 in decimal
  { 0,0,1,0,1,1,1,1 },  // = 47 in decimal
  { 1,0,0,0,1,1,1,1 },  // = 143 in decimal
  { 1,0,0,1,0,1,1,0 },  // = 150 in decimal
  { 1,0,0,1,1,0,1,1 },  // = 155 in decimal
  { 1,0,1,1,1,0,1,1 },  // = 187 in decimal
  { 1,0,0,0,1,1,0,0 },  // = 140 in decimal
  { 1,0,1,1,1,1,1,1 },  // = 191 in decimal
  { 1,0,0,1,1,1,1,0 },  // = 158 in decimal
 
  with decimal point
  { 1,1,1,1,1,1,0,1 },  // = 253 in decimal
  { 1,1,0,0,0,1,0,0 },  // = 196 in decimal
  { 0,1,1,0,1,1,1,1 },  // = 111 in decimal
  { 1,1,0,0,1,1,1,1 },  // = 207 in decimal
  { 1,1,0,1,0,1,1,0 },  // = 214 in decimal
  { 1,1,0,1,1,0,1,1 },  // = 219 in decimal
  { 1,1,1,1,1,0,1,1 },  // = 251 in decimal
  { 1,1,0,0,1,1,0,0 },  // = 204 in decimal
  { 1,1,1,1,1,1,1,1 },  // = 255 in decimal
  { 1,1,0,1,1,1,1,0 },  // = 158 in decimal




//  Just for further reference here are the
//  separate segment connections


  pin 2 = C
  pin 3 = DOT
  pin 4 = E
  pin 5 = F
  pin 6 = A
  pin 7 = B
  pin 8 = G
  pin 9 = D


*/


void setup() {
  // set the arduino pins to output so you
  // can control the shift register(s)
 
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
 
 
  //Turn on the serial Monitor - useful for debugging!
  Serial.begin(9600);
 
  //take the latch pin of the shift register(s) low
  digitalWrite(latchPin, HIGH);
 
  shiftOut(dataPin, clockPin, MSBFIRST, 0); // clears the 4th or secondUnits display
  shiftOut(dataPin, clockPin, MSBFIRST, 0); // clears the 3rd or secondTens display
  shiftOut(dataPin, clockPin, MSBFIRST, 0); // clears the 2nd or minutesUnits display
  shiftOut(dataPin, clockPin, MSBFIRST, 0); // clears the 1st or minutesTens display
 
  //take the latch pin of the shift register(s) high
  digitalWrite(latchPin, LOW);
}


void timerCountDown(){
 
        for (secondsUnits = 9; secondsUnits >= 0; secondsUnits--){
           
            // take the latch pin of the shift register low
            digitalWrite(latchPin, HIGH);   
           
            // Update the displays with the respective values
            shiftOut(dataPin, clockPin, MSBFIRST, seven_seg_digits[0][secondsUnits]);   
            shiftOut(dataPin, clockPin, MSBFIRST, seven_seg_digits[0][secondsTens]);
            shiftOut(dataPin, clockPin, MSBFIRST, seven_seg_digits[1][minutesUnits]);
            shiftOut(dataPin, clockPin, MSBFIRST, seven_seg_digits[0][minutesTens]);
           
            // take the latch pin high so the LEDs will light up:     
            digitalWrite(latchPin, LOW);
           
            // pause for a second before next value:
            delay(1000);
                     
            // for debugging send the count to the serial monitor
           
            Serial.print("Timer Count = ");
            Serial.print(minutesTens);
            Serial.print(minutesUnits);
            Serial.print(":");
            Serial.print(secondsTens);
            Serial.println(secondsUnits);       
           
            // check if the Seconds count is at 10
            // if it is decrement the Seconds Tens count
            // and reset the Minutes unit count to zero
 
            if (minutesTens == 6 && minutesUnits == 0 && secondsTens == 0 && secondsUnits == 0){
                Serial.println("you are here!");
                minutesTens = 5;
                minutesUnits = 9;
                secondsTens = 6;
                secondsUnits = 0;
                }   
           
            if (minutesTens == 0 && minutesUnits == 0 && secondsTens == 0 && secondsUnits == 0){
                minutesTens = 5;
                minutesUnits = 9;
                secondsTens = 6;
                secondsUnits = 0;
                }   
       
            if (minutesUnits == 0 && secondsTens == 0 && secondsUnits == 0){
                minutesTens--;
                minutesUnits = 9;
                }
                                 
            if (secondsTens == 0 && secondsUnits == 0){
               minutesUnits--;
               secondsTens = 6;
               }               
             
            if (secondsUnits == 0){
               secondsTens--;
               secondsUnits = 0;
               }                             
       }
}
   


void loop() {   
 
  // call the function timerCountDown!
  timerCountDown();



Im looking to get a countdown timer that will count down in Minutes to zero, outputting to a 4 LED 7 segment  Sure DE-DP004 LED display (74hc595 shift register)

I want to be able to control the timer count down to stop and start it remotely and also want to be able to ( again via IR remote) choose 3 different start durations ( 10min , 3 min and 1 min)

Any offers?

PaulMurrayCbr

Dude … don't do this.

Keep a value in seconds, starting from 180. Use the division and modulus operators to pull out the digits.

Code: [Select]

for(int seconds = 180; seconds >= 0; seconds--) {
  delay(1000);
  int minTens = (seconds / 600) % 6;
  int minOnes= (seconds / 60) % 10;
  int secTens = (seconds / 10) % 6;
  int minOnes= (seconds / 1) % 10;

  // rest of your code to stuff the correct digits out to your display goes here

}


Keep in mind that the arduino resonator is not as accurate as a crystal - one second isn't necessarily exactly 1000 ms.
http://paulmurraycbr.github.io/ArduinoTheOOWay.html

Delta_G

Code: [Select]
for (secondsUnits = 9; secondsUnits >= 0; secondsUnits--){

You start with secondsUnits at 9, so no wonder you start at 3:09
If at first you don't succeed, up - home - sudo - enter.

Go Up