0

so i am currently programming with Picaxe for my computer engineering class in high school. I currently have the code shown below to create a sort of tornado kind of effect but it is set to 1 speed. I am trying to make it so each time it returns to main and lowers each pause time for example by 50 so the tornado goes faster and faster each time it returns back to main. I know i need to use a decrement loop but i have no clue how to stick it in this code. Any help would be great. Thanks!

http://www.picaxe.com/BASIC-Commands/Program-Flow-Control/for/ - If i am correct i should be using the decrement loop from that, but no clue how to use it.

main:

            high b.4   'Turns on b.4 LED'
            pause 200  'LED Stays on for 200ms'
            low b.4    'Turns off LED'
            'No pause for smoother transition of LED's'

            high d.1 'Turns on  d.1 LED'
            pause 150 ' Pause for 150ms'
            low d.1,d.2,d.3,d.0 'Turns all other LED's off'
            pause 200 'Pause for 200ms'

            high d.2 'Turns on d.2 LED'
            pause 150 'Pause for 150ms'
            low d.1, d.2, d.3, d.0 'Turn off all other LED's'
            pause 200 'Pause for 200ms'

            high d.3 'Turns on d.3 LED' 
            pause 150 'Pause for 150ms'
            low d.1, d.2, d.3, d.0 'Turns off all other LED's'
            pause 200 'Pause for 200ms

            high d.0 'Turns on d.0'
            pause 150 'Pauses for 150ms'
            low d.1, d.2, d.3, d.0 'Turns off all other LED's'
            pause 200

    return main
Saro Taşciyan
  • 5,210
  • 5
  • 31
  • 50

1 Answers1

0

You need to have a for loop like this:

FOR b1 = 150 TO 50 STEP -5

This will give you a loop that ends when pauseTime <= 50, and will set b1 to 150, 145, 140...55, 50. That should make the LED's flash quicker, as long as your pause statements use the variable set in the FOR loop.

Tomtiger11
  • 53
  • 6
  • So that loop would keep going through the code and after each return the pause would be lowered by 5 until 50? – user3524328 Apr 11 '14 at 15:56
  • Almost. b1 would be lowered by 5 until 50. You'd need to pause by b1 every time. – Tomtiger11 Apr 11 '14 at 16:49
  • I'm also very confused to where i would actually enter that for loop.. very new to picaxe so any extra help with be awesome. Also do i need to use b1? or is that just an example you gave me? Since the LED's that i'm trying to do a tornado would be the D pin LED's – user3524328 Apr 11 '14 at 16:51
  • You can use any 'bx' where x is 0 - 9 (I think). You would put the LED on/off between the FOR statement and the end of the for statement (either 'Next' or EndFor', can't remember which one) – Tomtiger11 Apr 11 '14 at 17:42