Filed under: Programming
Now that the program is correctly set to a 24 hour clock format, the aim is to get the clock as accurate as possible. In the earlier programs I used ‘for next loop’ commands to set the time. The amount of times it loops determines how long the minute’s digit takes to count, which then triggers the other digits. Due to the amount of ‘let’ commands being repeated this effects how many loops are needed. The more let commands the fewer loops you need to time a minute. Much time was spent trying different amount of loops and amounts of ‘let’ commands to get as close as possible to one minute. It should be remembered that the amount of ‘let’ commands in the loop control the brightness and evenness of the four digits.
I recognised that by getting the minutes as accurate as possible allowed me to experiment with time over 12 hours. There were a number of different methods for getting within 30 seconds of real time over 12 hours. But in order for my clock to display the time accurately over months even years I need a method of timing it over 24 hours. I decided that if I could get the clock running, if anything a little, fast then I could use a ‘pause’ in the program after 24 hours to stop the clock for the amount of time it is fast. This then makes the clock accurate within seconds over 24 hours. The program above runs within a few seconds of real time over 24 hours but has to pause at midnight for four minutes. With more time I could experiment over a period of one week even one month and see how fast or slow the clock is. As long as it is fast in the first 24 hours it would just be a case of altering the pause to the exact amount its fast or slow.
Filed under: Programming
Trying to work out how and where to put a (if then) command in basic was very difficult. By identifying the need for a flow diagram it made this process easier. By directly using the flow chart I could identify where the command should be placed. By asking the questions do hours = 4 if no continue counting, but if yes ask another question. Do tens of hours = 2 if not continue counting but if yes start at 0. By combining two questions it was possible to start the hour’s digit at 0 after 23:59. Thus giving 00:00 at midnight on the 24 hour clock. The other problem with the previous program were the four digits not giving an even brightness, to rectify this problem the let pin= b0, b1, b2, b3 command was repeated in a different order. The hope was that putting them in a different sequence would even the brightness. This worked in practice also by repeating the sequence it also added to the brightness.
Filed under: Programming
The problem with the previous program was the hour’s digit on the 24hour clock. This counted 0 to 9 which = 9am and then counted 0 to 9 again which = 19:00pm which is fine, but instead of the hours resetting to 00:00 after 23:59 the hours digit continued counting upwards to 9 for example 24:00,25:00,26:00 etc. With the aid of this flowchart I aim to rectify the problem. Also the four digits are not equally bright, one is bright and the others are much dimmer.
Filed under: Programming
Counting the Time
In this program I have moved on from the previous stage. By referring to my hand drawn flow chart I was able to identify each stage of the counting process. By adding let b0= 31 at the beginning of label 41 it reset the counting on the minutes digit to zero and starts counting up to 9 again. Each time the minutes digit counts to 9 and resets it triggers the let b1= b1-1 which counts the tens of minutes digit. So every ten cycles the ten minute digit moves from 0 to 1 this continues to 5 and starts at 0 again. I then enter let b1= 47 at label 51 and b2= 79 at label 52 this process starts each of the digits at 0 after counting. Then it was just a case of counting each digit up to its correct number. From the tens of hours I counted 0 to 2 and for the hours 0 to 4. This gives the clock a 24 hour time display. On reflection I identified the need for the hours digit to count 0 to 9 twice and at 23:59 the hours digit needs to reset at 0.
Timing the Clock
This section of the program involved using for and next commands. These were used as tools to loop a section of the program. The program without these commands runs far too quickly to give a real time reading. These commands delay a section of the program by looping a number of times before continuing with the program. By selecting the amount of times I want these to loop dictates the timing of the minutes, which drives the other three digits. After experimenting with a stop watch I found two for next commands set at 150 were pretty accurate for setting the clock.
Filed under: Programming
This flowchart is used to keep in mind the sequence of how the program works, when using picaxe programming editor.
Filed under: Programming
This video shows the display counting from 0 to 9 on each digit. This is a step in the programming process. The stages in the programming can be seen below in the flow chart and in basic.
Filed under: Programming
The first stage of programming the clock involves simply getting the minute’s digit, which is the digit furthest on the right, to count from 0 to 9. Using the flow chart in programming editor I programmed the picaxe. In this program I used let B0= 32, B0 gives a pin its name and 32 is the binary code that sets the minutes digit to 0. By adding an, if then command into the program I was able to loop the program around. Each time the program looped around and did not = 22 it – 1 from 32 which enabled the clock to count upwards. When it reached 22 the, if then command, would repeat the process. The first program shows the flow diagram, the second program is the flow diagram converted into basic using picaxe programming editor.