Translate

Friday 31 October 2014

Meade EXT105 Telescope repair.

A while ago a friend contacted me with regards to a Meade telescope that belonged to a colleague of his. Time elapsed, and eventually it made it's way into the workshop.

This is some bit of kit. Now I'm no star-gazer (although I've always fancied the idea) but this thing looks fantastic. Once calibrated, you can search it's database and set it to automatically point in the right direction of the celestial body you wish to view. Brilliant..... except for this one, which threw a fit when asked to point to something, and smoke bilged out from the motor that makes it move up and down (I would say it's an EL or elevation motor, but apparently when dealing with telescopes, it's a DEC or declination motor, lord knows why).



Beast of a thing. First challenge was to get the optics out and placed to one side, out of harm's way... Two cap screws this side, and two the other hold the complete optics onto the base. It takes some gentle persuasion to extract them. 
There's some sort of electronics attached to the top of the optics ( not really sure of their purpose! Let me know! ) . This board and it's cover are held in place by a single cap screw. There's a 4 pin connector to undo to release it.



Once the optics are out we can disassemble the stand. Removing the cover off the motor for the DEC drive, reveals some damage!









Ugh... 
Unidentifiable burned-out IC's ...

We must never forget that electronics is driven by high-pressure smoke. You can see here where the failure has been caused by the smoke escaping from the IC's.

Emailing Meade and a few of their dealers gets me nowhere. Not even a reply. Thanks guys.


It does, however dawn on me, that the circuit that drives the Azimuth motor may be the same...



..and on closer inspection, it is certainly similar. The components are in a different position, but the circuit appears the same. 

By a process of elimination, the bits we need are a SI4947ADY & SI4936CDY. eBay is our friend. 

Each of these IC's house two MOSFETs. The SI4947ADY is P-channel and the SI4936CDY N-channel.


Having identified the parts, we give ourselves another problem! Which is which....

Having a careful look at the remains under a lupe, one IC gives us a clue, the SI4936CDY is on the left, the SI4947ADY in the middle (It's a 7805 voltage regulator on the right)



The old components are removed, and the board cleaned up. There's some damage to the print under the SI4947ADY in the middle. I have to add a tiny piece of wire here to make up the pad, and attempt to fit the IC on the top....





New IC's are fitted. I check for shorts & open circuit connections. It all checks out OK. The tiny wire under pin 1 is good to go!














 I decide to add a 0.01uF capacitor across the motor terminals to try and protect the electronics a little more from the spikes coming from the motor. I wouldn't mind betting this is what damaged the electronics in the first place.




... and then the daunting task of re-assembly. Nothing really to note here, other than be careful to route the wiring through the DEC motor board which connects to "the mystery electronics" on the top of the optics!

And then , bullet firmly between teeth.... Power-up!














  

WEM Watkins Copicat, repairs, renovations and electrical safety upgrades!

Minding my own business, when the telephone goes, and it's a friend with a wobbly Watkins that no longer works.


Cabinet's OK. Shabby chic. Hinges need replacing...
Obviously heavily gigged in smokey pubs! Tape path is dirty, and the heads are worn, but they'll go for a while yet.








Most of the caps in the supply are in poor condition. These two were replced, the originals being high ESR and low capacity. There were also two caps decoupling the +/- 12 volts rails. One was short circuit.
One of the main problems with the copicat, is it's lack-luster electrical safety. It was made back-in-the-day when standards were different. There's a nice metal box, the chassis of which is used to ground the audio incoming and outgoing. Now here's the issue. It's not grounded to a safety electrical earth. There's only a 2 core mains lead fitted. Now in this day and age , this isn't good enough. Not unless special precautions are taken (double insulated). This certainly isn't double insulated, and, although a remote possibility, if a live wire were to come off the motor or mains transformer, and connect with the metal chassis, the ground of your guitar would now be live. It's going to hurt, or kill. Not good. It HAS happened.

So, what can we do about it? Easy... fit a three core lead, and ground the chassis. Brilliant. Guitarist now safe. Except for the thing now hums like billy-o, because we now have an earth loop. More here.
OK, so what can we do? Remember the isolation transformer we fitted to the Ekco radio? Just the job. This will prevent any earth currents flowing , and prevent the thing humming whilst maintaining electrical safety. 

Here, I've fitted the isolation transformer , and a nice new 3-core mains lead. The Earth is secured to the chassis, using a soldered ring terminal, and a nut, bolt and star washer to ensure good contact
The tape-tensioning mechanism is stripped, cleaned and lubricated.









All cleaned up and ready for the next 30 years of service!




Wednesday 22 October 2014

Ekco U319 Radio Restoration.

I have one of these radios myself, and it sits in my hallway, minding it's own business. It's VHF doesn't work, and the speaker cloth is ghastly. But a friend of mine passed comment on it... "I've got one of those! Can you get it going for me?" Of course I can ....

Arrival. A few issues are immediately obvious. The case is cracked, the dial glass is broken, there's no pointer in the dial...









 Not much we can do about the crack, unless we fill it using car body filler, flat it and paint it up to look like bakelite.









Electronically, things are looking better...








 Chassis is removed and examined.
The on/off volume control is a replacement, but has worked lose, and has wrenched all it's wiring off, and the suppressor cap has long since exploded!.....







... Here's it's other end!










Plenty of horrible hunts. These have little cardboard sleeves, wrapped round little black caps, which interestingly have the value printed directly on the cap's body too!







The more traditional wax cap. They will all have to go!...

... as well as re-stuffing the electrolytic's where possible.


The mains smoother has been replaced in the past, with this expensive component! .... we'll see how it reforms....








... And after a few hours on the "Dreadnaught" capacitor reformer, it passes with flying colours, exhibiting correct capacity and acceptable ESR & leakage.














Case is removed....
 ... and given a bath
Chassis and dial is cleaned. Tuning is re-strung...
 ... and a dial pointer fabricated...
... capacitors changed, and electrically tested, medium wave and long wave working well, but no VHF reception....








VHF tuner is removed (a tedious job)...
 ... and a small decoupling capacitor is found to be electrically leaky (no surprise, it's a Hunts!) ... and VHF operation is restored...
















 This radio also has a "gram" setting. This allowed connection of a record player (gramophone) back in the day. My friend wished to connect it to his iPod. The gram input was originally electrically isolated from the live mains chassis by some (now replaced) capacitors. Now in this day and age, I'm not happy with one side of the chassis being connected to neutral, and using this method to isolate a hand held device.

So I've fitted a small audio isolation transformer, which is eventually fitted to a bracket by the IF transformer. This is checked with a megger tester to confirm isolation from the mains.






Now all that remains is to re-assemble and sit back and listen!


Caroline ... on 319!!!


.... now I really should look at mine ....






Thursday 9 October 2014

Thank You.

Thank to all the visitors to my website. There's been over 800 visits since it started, and I think that's nothing short of miraculous.

It amazes me the diverse countries that have visited. Everywhere from USA, UK, France, Germany, Russia, Argentina, Australia, Iraq, Thailand, Brazil, Canada, Indonesia, Romania. This list is constantly growing. I am humbled!

Coming up in the next few weeks:

1957 Ekco U341 repairs and restoration, and iPod modification.
WEM (Watkins) Copycat repairs and restoration.

I'm also planning on doing a bit about my 1978 Mini 1275GT, since the MOT (annual inspection) failed! Expect lots of pictures of corrosion here!

There's also a plan to add temperature monitoring to the pond pump controller. I'm slightly concerned that the pump may try to run if the water is frozen, and either damage the pump, or attempt to pump water over a frozen waterfall, and empty the pond.

There's a lot to do, and a lot to share, so pop back soon.

840 visits ... who'd have thought it ....







Sunday 7 September 2014

Simple TV using DG7-32 'scope tube

A while I go I set myself a challenge... to design an make a simple TV using only valves. Not a semiconductor in sight.

WARNING. Do NOT try this at home. This project calls for some high HT voltages. The main EHT rail is some 700 VDC. It will floor you or kill you if you come into contact with it. It will not warn you, blow a fuse, nor pull your safety trip. It may not give you a second chance. RESPECT IT'S AUTHORITY

I will not, under any circumstances, accept any liability if you decide to re-create this project for yourself.

I procured an electrostatically deflected DG7-32 oscilloscope tube from the usual sources, a base , a handful of very nice Russian 6N1P valves, a couple of EF91s and a ECL83 for the sound. An EZ81 provides (some) rectification. Enter some transformers from the scrap bin, some tag strips and a couple of scrap aluminium enclosures.

My first design was too complicated, used too many valves, and, most importantly didn't work.

 

You'll notice a few things:

1) The raster is all "in one corner", this is because I didn't employ a differential drive to the X &Y plates.
2) There's precious little video modulation. I gave most of it away to Miller capacitance.

All-in-all, rubbish.

It sat on a shelf for a year, sneering at me.

I took it to pieces, and completely re-vamped it. I'd subsequently robbed the mains transformers for another project, so I ended up with a nice transformer from an old audio amplifier to provide the +300V and 6.3V for the heaters. I also needed to develop the 700 V EHT. In the original design I had a separate transformer, with a nice high voltage winding and an isolated heater winding. No such luck this time. I had a small insolating transformer from an old bathroom shaver point. 240VAC in, 240VAC out. This would have to do.

Let's have a quick look at the schematic:-




Yeah, you're going to want to zoom in on that a bit...


The Power Supply

Mains comes in and is fused by F1. TR2 and TR3 are actually one transformer, with centre-tapped heaters and HT winding. R1 and R2 provide a little peak current limiting to keep our EZ81 rectifier happy. The cathode of the rectifier is connected to our main smoothing capacitor C1. This must be no larger than 50uF, so 22uF is fine here, and we're not pulling much current. R3 and C2 provide additional filtering, and R4 and C3 provide a lower voltage supply for the screens of our video amplifiers. TR1 is the shaver transformer, and provides and quick and dirty 350V supply via D1 and C4. This 350V supply is not referenced to earth, but our 300V HT supply, giving around 650 VDC (More like 700VDC off-load)

I'll repeat my warning at the start of the article at this point. This power supply is more than capable of supplying enough current to kill you. Yes. Really. This means you. Don't do it. 

Whilst I was developing this gadget, I kept a voltmeter permanently attached between GND and 700V. Also, I kept a 10W 10K resistor connected to GND, and to an insulated lead, which was connected to the +700 VDC rail whilst I was working on the circuit. I've also installed 2x220K resistors in series directly across C1, C2 and C4 to bleed away any charge within a few minutes. These resistors aren't shown on the diagram. 

The original version also had separate fuses for each HT supply, and, stupidly, for the EHT supply. I used the ordinary type of 20mm fuse. During development, I inadvertently shorted out the EHT supply. The 20mm fuse blew violently, vapourising the wire against the inside of the glass, which carried on conducting! The resulting burned mess of fuseholder resulted in a lesson learned. Fuses have voltage ratings. 20mm fuses are rated to 250V. 

The Signal Stages.

Video comes in on X1, and is loaded by a 75 ohm resistor. Video is passed via C1 to the grid of our first video amplifier VT2, an EF91 (6AM6) pentode. This is further amplified by VT3 and passed to the first grid of the CRT. 

Video is also taken from VT2 to VT4a, the sync amplifier. Here some of the video information is lost (mainly through miller capacitance), but the line and frame sync pulses are retained. The sync pulses are passed from the anode load to VT4b, the frame sync separator, whereby the higher frequency line sync pulses are filtered out by C13 and R19, and the remaining frame sync pulses are used to sync the fantastron oscilator formed by VT5a & VT5b. This gives us a nice sawtooth waveform, locked to our video frames at 50Hz (in the UK). Although I haven't tried it, I'm sure it will work just fine with NTSC at 60Hz.

The frame sawtooth waveform is then passed to VT9A & VT10B (what happened there? It should read VT9B!)  which forms a differential amplifier and drives the Y-plates of the CRT. The plates are coupled to the anodes of the differential amplifier by 10nF, 1.6KV capacitors, as the deflection plates are referenced to the EHT by R46 and R47.

The sync pluses are also fed from VT4a via a high pass filter formed by C16-19 and R23-26, to pass the line sync pulses, to another fantastron amplifier, this time synced to the line pulses at 15.625 KHZ (again, I've not tried it, but it should be OK with NTSC too).  Once again this syncs another fantastron oscillator, and provides us with our sawtooth waveform to drive the X-plates via differential amplifier VT7a and VT8b (Again? This should read VT7B!)

The CRT is provided with a focus voltage via R50, and the cathode is supplied by R51 to slightly elevate it above 0V, to allow our negative going video to modulate the grid. 

Audio is provided by a very simple ECL83 amplifier. It's not going to win any awards for design or performance, but it functions. The output transformer is simply a 9V mains transformer. I know all about the fact that the transformer is totally unsuitable due to DC on the windings etc etc, but I had it to hand, and it works! 

Construction is fugly to say the least. 











I intended it to be a sort of homage to the home constructor of the 1940's / 1950's. 










There it is... exposed HT wiring an' all...














Performace isn't fantastic. The circuit is simple, the tube was never designed to show a raster scanned image... but it's definitely Dr. Sheldon Cooper!







Some retrace (flyback) lines are visible, as there's no supression. 








Feeling cheated? Yes, me too. I promised a design with no semiconductors, and yet the EHT rectifier is clearly a grain of sand. As I said originally, the EHT was originally supplied by a separate transformer, and this allowed me to use a valve rectifier (I actually used an EZ80), and I elevated it's heater winding to 350VDC, so as not to compromise the heater/cathode insulation. I did try putting the EZ80 into this circuit (if you look carefully you can still see it's Noval base below the speaker magnet) but the heater cathode insulation was just not good enough to hold off the ~700 volts and flashed over :(

Saturday 30 August 2014

Arduino Astronomical Clock (or Arduino Pond Pump Controller!)

****** A lot of people land on this page. Welcome. There are a few updates on this project (the last being here.) so it's worth checking through the blog for updates. Thanks ******




It's been a great summer here in the UK. I built myself something I'd always wanted. A bit of a water feature in my garden. The sound of trickling water whilst relaxing in the garden ... ahhhh !

Well, I didn't like the thought of the pump running all night, wasting all that precious energy, so a solution was required....

The usual thoughts of a photodiode (even an led works as a photodiode, try it!) or LDR and comparator were soon dispelled, as I'd done such things as a kid, and it's a horrible thing to set up. Clouds causing shadows, neighbours outside lights switching it on etc etc ... no , we need something a little more sophisticated.

Now, a guy called Paul had done the same thing, but backwards (switching something on at dusk, and off at dawn), and his website here shows a rather nice unit built using recycled bits and pieces. "Just the job".. except I need more coding experience, so I blatantly copy some of Paul's thoughts and the use of the Timelord library.

Although I love the idea of recycling the display, I just don't have anything to recycle at present, other than the usual 2 x 16 LCD I've removed from a DAB radio, and a nice rotary encoder, so we'll go with those.

Now, keeping time....

This is a DS1307 module, purchased at very little expense (but a bit of a wait) on eBay. It's a fully fledged real-time clock, which sends it's data via an I2C interface. Just the job. On the rear of this fella is a button cell holder. Just beware. Order yours with the battery. You can get a version which takes an ordinary 2023 Lithium coin cell, or an LIR2023 Lithium-ion coin cell, which charges off the supplied 3.3 or 5 volts. Don't try and charge an ordinary 2023 cell. It won't be pretty.


OK, so that's our time keeping sorted.

So, time to conjure up some hardware....




My 5v supply is a little buck converter, which is driven from the 24VAC from the pond transformer. The Arduino (Nano in this example) is mounted on a bit of perf board, along with a relay module and the DS1307 RTC board.
















Now copy the code into your IDE, and alter the LATITUDE and LONGITUDE constants to your position on the planet. Google maps comes in handy here, or just pop outside with a GPS.
Upload the code (below) and your display should show something like this. American users may wish to note the date is in the UK standard (DD/MM/YYYY), you can, of course, alter the code to suit your own preferred format.

Now, if that's not UTC (and unless you're in the UK in winter, or your PC is set to UTC, it won't be) press and hold the button for 5 seconds. When you release the button the display will show "Set Year". You can alter this using the rotary encoder. If the encoder works back to front, reverse the wires to pins D2 & D3 on the Arduino board. Pressing the button moves the menu on to set Month. Pressing again, set the day, then hour and then minute. Once the minute is set the RTC is set, and the clock display will revert after 1 second. Excellent. The clock is now set and running.

Pressing and releasing the button once will display the current calculated sun rise and sunset time.

If you wait the display will revert back to the clock after a few seconds.

Pressing again whilst the sunrise and sunset times are display will allow you to alter the mode of the clock. Auto switches the output on when the sun rises, and off when it sets.
On switches the output on permanently. Finally off leaves the output off.


Finally, mount the whole shooting match on the wall, make it neat and go for a pint or two to celebrate!















Here's the code:

// Dawn & Dusk controller.
// 16th August 2014.
// (C) A.G.Doswell 2014
//
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
//
// Designed to control a relay connected to pin A3. Pin goes low during daylight hours and high during night. Relay uses active low, so is
// "On" during the day. This is connected to the fountain pump in my garden.
//
// Time is set using a rotary encoder with integral push button. The Encoder is connected to interrupt pins D2 & D3 (and GND), 
// and the push button to pin analogue 0 (and GND)
// The RTC is connections are: Analogue pin 4 to SDA. Connect analogue pin 5 to SCL.
// A 2 x 16 LCD display is connected as follows (NOTE. This is NOT conventional, as interrupt pins are required for the encoder)
//  Arduino LCD  
//  D4      DB7
//  D5      DB6
//  D6      DB5
//  D7      DB4
//  D12     RS
//  D13     E
//
// Use: Pressing and holding the button will enter the clock set mode (on release of the button). Clock is set using the rotary encoder. 
// The clock must be set to UTC.
// Pressing and releasing the button quickly will display the current sun rise and sun set times. Pressing the button again will enter the mode select menu. 
// Modes are AUTO: On when the sun rises, off when it sets.
//           ON: Permanently ON
//           OFF: Permanently OFF (Who'd have guessed it?)
//
// Change the LATTITUDE and LONGITUDE constant to your location.

#include <Wire.h>
#include "RTClib.h" // from https://github.com/adafruit/RTClib
#include <LiquidCrystal.h>
#include <Encoder.h> // from http://www.pjrc.com/teensy/td_libs_Encoder.html
#include <TimeLord.h> // from http://swfltek.com/arduino/timelord.html. When adding it to your IDE, rename the file, removing the "-depreciated" 

RTC_DS1307 RTC; // Tells the RTC library that we're using a DS1307 RTC
Encoder knob(2, 3); //encoder connected to pins 2 and 3 (and ground)
LiquidCrystal lcd(12, 13, 7, 6, 5, 4); // I used an odd pin combination because I need pin 2 and 3 for the interrupts.
//the variables provide the holding values for the set clock routine
int setyeartemp; 
int setmonthtemp;
int setdaytemp;
int sethourstemp;
int setminstemp;
int setsecs = 0;
int maxday; // maximum number of days in the given month
int TimeMins; // number of seconds since midnight
int TimerMode = 2; //mode 0=Off 1=On 2=Auto
int TimeOut = 10;
int TimeOutCounter;

// These variables are for the push button routine
int buttonstate = 0; //flag to see if the button has been pressed, used internal on the subroutine only
int pushlengthset = 3000; // value for a long push in mS
int pushlength = pushlengthset; // set default pushlength
int pushstart = 0;// sets default push value for the button going low
int pushstop = 0;// sets the default value for when the button goes back high

int knobval; // value for the rotation of the knob
boolean buttonflag = false; // default value for the button flag


const int TIMEZONE = 0; //UTC
const float LATITUDE = 51.89, LONGITUDE = -2.04; // set YOUR position here 
int Sunrise, Sunset; //sunrise and sunset expressed as minute of day (0-1439)
TimeLord myLord; // TimeLord Object, Global variable
byte sunTime[]  = {0, 0, 0, 1, 1, 13}; // 17 Oct 2013
int SunriseHour, SunriseMin, SunsetHour, SunsetMin; //Variables used to make a decent display of our sunset and sunrise time.

void setup () {
    //Serial.begin(57600); //start debug serial interface
    Wire.begin(); //start I2C interface
    RTC.begin(); //start RTC interface
    lcd.begin(16,2); //Start LCD (defined as 16 x 2 characters)
    lcd.clear(); 
    pinMode(A0,INPUT);//push button on encoder connected to A0 (and GND)
    digitalWrite(A0,HIGH); //Pull A0 high
    pinMode(A3,OUTPUT); //Relay connected to A3
    digitalWrite (A3, HIGH); //sets relay off (default condition)
    
    //Checks to see if the RTC is runnning, and if not, sets the time to the time this sketch was compiled.
    if (! RTC.isrunning()) {
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
 
 
    //Timelord initialisation
    myLord.TimeZone(TIMEZONE * 60);
    myLord.Position(LATITUDE, LONGITUDE);
    CalcSun ();
}
           

void loop () {
  
    DateTime now = RTC.now(); //get time from RTC
    //Display current time
    lcd.setCursor (0,0);
    lcd.print(now.day(), DEC);
    lcd.print('/');
    lcd.print(now.month());
    lcd.print('/');
    lcd.print(now.year(), DEC);
    lcd.print("    ");
    lcd.setCursor (0,1);
    lcd.print(now.hour(), DEC);
    lcd.print(':');
    if (now.minute() <10) 
      {
        lcd.print("0");
      }
    lcd.print(now.minute(), DEC);
    lcd.print(':');
    if (now.second() <10) 
      {
        lcd.print("0");
      }
    lcd.print(now.second());
    lcd.print("     ");
    
    //current time in minutes since midnight (used to check against sunrise/sunset easily)
    TimeMins = (now.hour() * 60) + now.minute();
    
    // Calculate sun times once a day at a minute past midnight
    if (TimeMins == 1) {
      CalcSun ();
    }
    if (TimerMode ==2) {
      if (TimeMins >= Sunrise && TimeMins <=Sunset-1) { //If it's after sunrise and before sunset, switch our relay on
          digitalWrite (A3, LOW);
          lcd.setCursor (13,1);
          lcd.print ("On ");
        }
        else {  //otherwise switch it off
          digitalWrite (A3, HIGH);
          lcd.setCursor (13,1);
          lcd.print ("Off");
        }
      }
       if (TimerMode ==0) {
         digitalWrite (A3, HIGH);
         lcd.setCursor (13,1);
         lcd.print ("Off");
       }
     
       if (TimerMode ==1) {
         digitalWrite (A3, LOW);
         lcd.setCursor (13,1);
         lcd.print ("On ");
       }
    
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    delay (10);
    
    if (pushlength <pushlengthset) {
     
      ShortPush ();   
    }
    
       
       //This runs the setclock routine if the knob is pushed for a long time
       if (pushlength >pushlengthset) {
         lcd.clear();
         DateTime now = RTC.now();
         setyeartemp=now.year(),DEC;
         setmonthtemp=now.month(),DEC;
         setdaytemp=now.day(),DEC;
         sethourstemp=now.hour(),DEC;
         setminstemp=now.minute(),DEC;
         setclock();
         pushlength = pushlengthset;
       };
}

//sets the clock
void setclock (){
   setyear ();
   lcd.clear ();
   setmonth ();
   lcd.clear ();
   setday ();
   lcd.clear ();
   sethours ();
   lcd.clear ();
   setmins ();
   lcd.clear();
   
   RTC.adjust(DateTime(setyeartemp,setmonthtemp,setdaytemp,sethourstemp,setminstemp,setsecs));
   CalcSun ();
   delay (1000);
   
}

// subroutine to return the length of the button push.
int getpushlength () {
  buttonstate = digitalRead(A0);  
       if(buttonstate == LOW && buttonflag==false) {     
              pushstart = millis();
              buttonflag = true;
          };
          
       if (buttonstate == HIGH && buttonflag==true) {
         pushstop = millis ();
         pushlength = pushstop - pushstart;
         buttonflag = false;
       };
       return pushlength;
}
// The following subroutines set the individual clock parameters
int setyear () {
   lcd.setCursor (0,0);
    lcd.print ("Set Year");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      return setyeartemp;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) { //bit of software de-bounce
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    setyeartemp=setyeartemp + knobval;
    if (setyeartemp < 2014) { //Year can't be older than currently, it's not a time machine.
      setyeartemp = 2014;
    }
    lcd.print (setyeartemp);
    lcd.print("  "); 
    setyear();
}
  
int setmonth () {

   lcd.setCursor (0,0);
    lcd.print ("Set Month");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      return setmonthtemp;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) {
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    setmonthtemp=setmonthtemp + knobval;
    if (setmonthtemp < 1) {// month must be between 1 and 12
      setmonthtemp = 1;
    }
    if (setmonthtemp > 12) {
      setmonthtemp=12;
    }
    lcd.print (setmonthtemp);
    lcd.print("  "); 
    setmonth();
}

int setday () {
  if (setmonthtemp == 4 || setmonthtemp == 5 || setmonthtemp == 9 || setmonthtemp == 11) { //30 days hath September, April June and November
    maxday = 30;
  }
  else {
  maxday = 31; //... all the others have 31
  }
  if (setmonthtemp ==2 && setyeartemp % 4 ==0) { //... Except February alone, and that has 28 days clear, and 29 in a leap year.
    maxday = 29;
  }
  if (setmonthtemp ==2 && setyeartemp % 4 !=0) {
    maxday = 28;
  }
  
   lcd.setCursor (0,0);
    lcd.print ("Set Day");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      return setdaytemp;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) {
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    setdaytemp=setdaytemp+ knobval;
    if (setdaytemp < 1) {
      setdaytemp = 1;
    }
    if (setdaytemp > maxday) {
      setdaytemp = maxday;
    }
    lcd.print (setdaytemp);
    lcd.print("  "); 
    setday();
}

int sethours () {
    lcd.setCursor (0,0);
    lcd.print ("Set Hours");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      return sethourstemp;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) {
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    sethourstemp=sethourstemp + knobval;
    if (sethourstemp < 1) {
      sethourstemp = 1;
    }
    if (sethourstemp > 23) {
      sethourstemp=23;
    }
    lcd.print (sethourstemp);
    lcd.print("  "); 
    sethours();
}

int setmins () {

   lcd.setCursor (0,0);
    lcd.print ("Set Mins");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      return setminstemp;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) {
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    setminstemp=setminstemp + knobval;
    if (setminstemp < 0) {
      setminstemp = 0;
    }
    if (setminstemp > 59) {
      setminstemp=59;
    }
    lcd.print (setminstemp);
    lcd.print("  "); 
    setmins();
}

int setmode () { //Sets the mode of the timer. Auto, On or Off

    lcd.setCursor (0,0);
    lcd.print ("Set Mode");
    pushlength = pushlengthset;
    pushlength = getpushlength ();
    if (pushlength != pushlengthset) {
      return TimerMode;
    }

    lcd.setCursor (0,1);
    knob.write(0);
    delay (50);
    knobval=knob.read();
    if (knobval < -1) {
      knobval = -1;
    }
    if (knobval > 1) {
      knobval = 1;
    }
    TimerMode=TimerMode + knobval;
    if (TimerMode < 0) {
      TimerMode = 0;
    }
    if (TimerMode > 2) {
      TimerMode=2;
    }
    if (TimerMode == 0) {
    lcd.print("Off");
    lcd.print("  "); 
    }
    if (TimerMode == 1) {
    lcd.print("On");
    lcd.print("  "); 
    }
    if (TimerMode == 2) {
    lcd.print("Auto");
    lcd.print("  "); 
    }
    setmode ();
}

int CalcSun () { //Calculates the Sunrise and Sunset times
    DateTime now = RTC.now();
    sunTime[3] = now.day(); // Give Timelord the current date
    sunTime[4] = now.month();
    sunTime[5] = now.year();
    myLord.SunRise(sunTime); // Computes Sun Rise.
    Sunrise = sunTime[2] * 60 + sunTime[1]; // Sunrise returned in minutes past midnight
    SunriseHour = sunTime[2];
    SunriseMin = sunTime [1];
    sunTime[3] = now.day(); // Uses the Time library to give Timelord the current date
    sunTime[4] = now.month();
    sunTime[5] = now.year();
    myLord.SunSet(sunTime); // Computes Sun Set.
    Sunset = sunTime[2] * 60 + sunTime[1]; // Sunset returned in minutes past midnight
    SunsetHour = sunTime[2];
    SunsetMin = sunTime [1];
}

void ShortPush () {
  //This displays the calculated sunrise and sunset times when the knob is pushed for a short time.
for (long Counter = 0; Counter < 604 ; Counter ++) { //returns to the main loop if it's been run 604 times 
                                                     //(don't ask me why I've set 604,it seemed like a good number)
  lcd.setCursor (0,0);
  lcd.print ("Sunrise ");
  lcd.print (SunriseHour);
  lcd.print (":");
  if (SunriseMin <10) 
     {
     lcd.print("0");
     }
  lcd.print (SunriseMin);
  lcd.setCursor (0,1);
  lcd.print ("Sunset ");
  lcd.print (SunsetHour);
  lcd.print (":"); 
    if (SunsetMin <10) 
     {
     lcd.print("0");
     }
  lcd.print (SunsetMin);        

    
  //If the knob is pushed again, enter the mode set menu
  pushlength = pushlengthset;
  pushlength = getpushlength ();
  if (pushlength != pushlengthset) {
    lcd.clear ();
    TimerMode = setmode ();

  }
  
}

}