For Next Problem
bluejay
Posts: 131
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
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
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.