Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

shift leds

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
pvdbos

Bascom Member



Joined: 25 Nov 2006
Posts: 96
Location: Edam

netherlands.gif
PostPosted: Thu Oct 30, 2014 8:38 pm    Post subject: shift leds Reply with quote

Hello all,
is it possible to shift 4 leds to left or right?
I do now with this code:

Rood Alias Portc.7 'LED
Blauw Alias Portc.6 'LED
Groen Alias Portc.5 'LED
Oranje Alias Portc.4 'LED

Config Portc.4 = Output 'Blauwe LED
Config Portc.5 = Output 'Rode LED
Config Portc.6 = Output 'Groene LED
Config Portc.7 = Output 'Oranje LED


Sub Leds
For X = 1 To 6
Toggle Groen
Waitms 125
Toggle Groen
Toggle Rood
Waitms 125
Toggle Rood
Toggle Blauw
Waitms 125
Toggle Blauw
Toggle Oranje
Waitms 125
Toggle Oranje
Next
End Sub

but is there an higher code level with shift or something?


(BASCOM-AVR version : 2.0.7.7 )

_________________
http://www.hobbyrobots.nl
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Thu Oct 30, 2014 8:44 pm    Post subject: Reply with quote

wow that looks complex for something simple Smile
ok i did not actually looked long at the code but try this instead:

Code:
do
  for x=4 to 7  'the leds
      set portc.x  'set led on
      waitms 125
      reset portc.x  'led off
  next
loop

_________________
Mark
Back to top
View user's profile Visit poster's website
pvdbos

Bascom Member



Joined: 25 Nov 2006
Posts: 96
Location: Edam

netherlands.gif
PostPosted: Thu Oct 30, 2014 9:13 pm    Post subject: Reply with quote

Mark

the 4 other ports they are not affected with this code?
they are used for something else.

_________________
http://www.hobbyrobots.nl
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Thu Oct 30, 2014 9:17 pm    Post subject: Reply with quote

do you understand the code?
please have a good look at it. if you do not understand a part let me know.

_________________
Mark
Back to top
View user's profile Visit poster's website
pvdbos

Bascom Member



Joined: 25 Nov 2006
Posts: 96
Location: Edam

netherlands.gif
PostPosted: Thu Oct 30, 2014 9:37 pm    Post subject: Reply with quote

Yes I understand the code but I think to difficult
when I see an example then it's easy.

_________________
http://www.hobbyrobots.nl
Back to top
View user's profile Visit poster's website
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Thu Oct 30, 2014 11:44 pm    Post subject: Reply with quote

A comment about the general principles here, not about this particular problem:

The aim of programming should be to get a computer to do the repetitive tasks we dont want to do. So we should avoid repetitive programming, let the computer do that !

This is a general problem in many 'high level' programming languages. In particular in languages which use objects, its almost mandatory to name the objects, and then have to treat them individually, by name. The concept of using a simple loop to access each object is almost forgotten.

I see the same in many posts where people have constructed a huge list of commands, or a very large select...case statement, to access a list of operations, where a simple loop through an array with an index would be far more efficient.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum