Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:18 24 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Efficient code

Author Message
Talbit
Senior Member

Joined: 07/06/2011
Location: Australia
Posts: 210
Posted: 01:32am 25 Nov 2011
Copy link to clipboard 
Print this post

Gents,
Is there a more elegant way to write this code?
It’s just meant to toggle each MM pin high for ½ second, continuously as a test.
I haven't actually tried it as such but I guess it should work.
Thanks
Talbit
10 FOR i = 1 TO 20 : SETPIN i, 8 : NEXT i
20 Pin (1)=1
30 PAUSE 500
40 PIN (1)=0
50 Pin (2)=1
60 PAUSE 500
70 PIN (2)=0
80 Pin (3)=1
90 PAUSE 500
100 PIN (3)=0
110 Pin (4)=1
120 PAUSE 500
130 PIN (4)=0
140 Pin (5)=1
150 PAUSE 500
160 PIN (5)=0
170 Pin (6)=1
180 PAUSE 500
190 PIN (6)=0
200 Pin (7)=1
210 PAUSE 500
220 PIN (7)=0
230 Pin (8)=1
240 PAUSE 500
250 PIN (8)=0
260 Pin (9)=1
270 PAUSE 500
280 PIN (9)=0
290 Pin (10)=1
300 PAUSE 500
310 PIN (10)=0
320 Pin (11)=1
330 PAUSE 500
340 PIN (11)=0
350 Pin (12)=1
360 PAUSE 500
370 PIN (12)=0
380 Pin (13)=1
390 PAUSE 500
400 PIN (13)=0
410 Pin (14)=1
420 PAUSE 500
430 PIN (14)=0
440 Pin (15)=1
450 PAUSE 500
460 PIN (15)=0
470 Pin (16)=1
480 PAUSE 500
490 PIN (16)=0
500 Pin (17)=1
510 PAUSE 500
520 PIN (17)=0
530 Pin (18)=1
540 PAUSE 500
550 PIN (18)=0
560 Pin (19)=1
570 PAUSE 500
580 PIN (19)=0
590 Pin (20)=1
600 PAUSE 500
610 PIN (20)=0
620 Goto 20


Talbit
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 01:58am 25 Nov 2011
Copy link to clipboard 
Print this post

Well, Talbit,

You used a FOR...NEXT loop for the setpin command, why not use a similar loop to toggle the pins?


FOR X = 1 TO 20: PIN(X)=1:PAUSE 500:PIN(X)=0:NEXT X


Then if you want to you can change the GOTO at line 620, into a DO/LOOP construct.

15 DO
.
.
.
.
620 LOOP


Regards,
Bob Devries
Dalby, QLD, Australia
 
Talbit
Senior Member

Joined: 07/06/2011
Location: Australia
Posts: 210
Posted: 03:32am 25 Nov 2011
Copy link to clipboard 
Print this post

Bob,
Beautiful elegance and all on one line!
You're the master!
Thank you
Talbit
Talbit
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024