Help wanted to implement a switch in my code
Archiver
Posts: 46,084
Hi..
I am a newcomer and I need starting help.
Can anybody show me how I imlement three pushbuttons in my code?
Like this:
First pushbutton:
(to step thru the colours)
Push 1 = red only
Push 2 = red and green only
Push 3 = green only
Push 4 = green and blue only
Push 5 = blue only
Push 6 = red and blue only
Push 7 = start the sequenz
Push 8 = off
Second pushbutton: (changed the worth named "a")
Push = Speed up
Third pushbutton: (changed the worth named "a")
Push = speed down
And this is my code:
cut
'
======================================================================
'
' Changes the brightness of LED`s using PWM
'
' {$STAMP BS2}
'
======================================================================
Pin0 CON 0 'LED red
Pin1 CON 1 'LED green
Pin2 CON 2 'LED blue
level VAR Byte
a VAR Byte
'
DlyTm CON 0 'Pause
a = 1 'Steps
'
Main:
High Pin0 'LED red on / red on
Low Pin1 'LED green off
Low Pin2 'LED blue off
Loop:
FOR level = 0 TO 255 Step a 'LED green up / red and green on
PWM Pin1,level,25
PAUSE DlyTm
NEXT
FOR level = 255 TO 0 Step a 'LED red down / green on
PWM Pin0,level,25
PAUSE DlyTm
NEXT
Low Pin0 'LED red off
FOR level = 0 TO 255 Step a 'LED blue up / green and blue on
PWM Pin2,level,25
PAUSE DlyTm
NEXT
FOR level = 255 TO 0 Step a 'LED green down / blue on
PWM Pin1,level,25
PAUSE DlyTm
NEXT
Low Pin1 'LED green off
FOR level = 0 TO 255 Step a 'LED red up / blue and red on
PWM Pin0,level,25
PAUSE DlyTm
NEXT
FOR level = 255 TO 0 Step a 'LED blue down / red on
PWM Pin2,level,25
PAUSE DlyTm
NEXT
Low Pin2 'LED blue off
GOTO Loop
END
cut
Thanks for help.
Best regards, Kai
I am a newcomer and I need starting help.
Can anybody show me how I imlement three pushbuttons in my code?
Like this:
First pushbutton:
(to step thru the colours)
Push 1 = red only
Push 2 = red and green only
Push 3 = green only
Push 4 = green and blue only
Push 5 = blue only
Push 6 = red and blue only
Push 7 = start the sequenz
Push 8 = off
Second pushbutton: (changed the worth named "a")
Push = Speed up
Third pushbutton: (changed the worth named "a")
Push = speed down
And this is my code:
cut
'
======================================================================
'
' Changes the brightness of LED`s using PWM
'
' {$STAMP BS2}
'
======================================================================
Pin0 CON 0 'LED red
Pin1 CON 1 'LED green
Pin2 CON 2 'LED blue
level VAR Byte
a VAR Byte
'
DlyTm CON 0 'Pause
a = 1 'Steps
'
Main:
High Pin0 'LED red on / red on
Low Pin1 'LED green off
Low Pin2 'LED blue off
Loop:
FOR level = 0 TO 255 Step a 'LED green up / red and green on
PWM Pin1,level,25
PAUSE DlyTm
NEXT
FOR level = 255 TO 0 Step a 'LED red down / green on
PWM Pin0,level,25
PAUSE DlyTm
NEXT
Low Pin0 'LED red off
FOR level = 0 TO 255 Step a 'LED blue up / green and blue on
PWM Pin2,level,25
PAUSE DlyTm
NEXT
FOR level = 255 TO 0 Step a 'LED green down / blue on
PWM Pin1,level,25
PAUSE DlyTm
NEXT
Low Pin1 'LED green off
FOR level = 0 TO 255 Step a 'LED red up / blue and red on
PWM Pin0,level,25
PAUSE DlyTm
NEXT
FOR level = 255 TO 0 Step a 'LED blue down / red on
PWM Pin2,level,25
PAUSE DlyTm
NEXT
Low Pin2 'LED blue off
GOTO Loop
END
cut
Thanks for help.
Best regards, Kai