Better coding

Tony P

Member
How could I shorten the following code?

I have made an electromagnetic pendulum clock and am using an 18M2 to control the pulses and timing.
This is a section of code that I use to count the actual seconds (RTC) and the amount of pulses sent to the pendulum.
The pendulum is deliberately set to run slightly fast and after each minute a correction is made if required.


Code:
IF SECONDS=$1 THEN LET SEC_COUNT=1:ENDIF
IF SECONDS=$2 THEN LET SEC_COUNT=2:ENDIF
IF SECONDS=$3 THEN LET SEC_COUNT=3:ENDIF
IF SECONDS=$4 THEN LET SEC_COUNT=4:ENDIF
IF SECONDS=$5 THEN LET SEC_COUNT=5:ENDIF
IF SECONDS=$6 THEN LET SEC_COUNT=6:ENDIF
IF SECONDS=$7 THEN LET SEC_COUNT=7:ENDIF
IF SECONDS=$8 THEN LET SEC_COUNT=8:ENDIF
IF SECONDS=$9 THEN LET SEC_COUNT=9:ENDIF
IF SECONDS=$10 THEN LET SEC_COUNT=10:ENDIF
;ETC UP TO $60
 

techElder

Well-known member
Why are "SECONDS" incrementing in HEX representation different than incrementing in DECIMAL representation? Are you reading something that's coded output is represented in HEX?
 

PieM

Senior Member
Var_Temp =SECONDS/16 * 10
SEC_COUNT = SECONDS//16
SEC_COUNT = Var_Temp + SEC_COUNT
 
Top