Shop OBEX P1 Docs P2 Docs Learn Events
For Next Problem — Parallax Forums

For Next Problem

bluejaybluejay Posts: 131
edited 2011-11-28 14:47 in BASIC Stamp
An LED is connected to a 220 ohm resistor to output 7. This code for a BS2 will increase brightness for the LED then repeat continously.

reps VAr Byte

main:
FOR reps = 1 TO 300 'increase LED brightness
PULSOUT 7, reps
DEBUG DEC ? reps
NEXT

To decreasebrightness the statement "FOR reps = 1 TO 300 " should be replaced by "FOR reps = -1 TO 0.

Could somebody please come up with a code that will include both FOR staments so that after the LED increases the maximun brightness the LED will immediately start decreasing it's brightness and continue the loop, or a better way of solving this problem?
I will appreciate a solution. Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-11-28 10:28
    To decrease brightness, you need this instead of what you mentioned:

    FOR reps = 300 to 1 step -1

    To increase brightness, then decrease brightness, you need one loop to increase brightness followed by another loop to decrease brightness. You can put another loop (probably DO / LOOP) around the two FOR loops.
  • ercoerco Posts: 20,256
    edited 2011-11-28 14:47
    FYI, your debug statement is seriously slowing down your program execution. If you want to change the timing and apparent brightness, comment it out with a leading apostrophe and run that program.
Sign In or Register to comment.