inglewoodpete
Senior Member
I think the following code will do what you want.
Creo que el código se va a hacer lo que quieres.
The code assumes that you will use Pin C.0 as the button input. The input needs a pull down resistor to the 0v line. The button is connected between the input and the +5v and a press pulls the input high. I have used interrupts to capture the button press. The routine uses two bit variables to ensure that the button is released before the routine changes to the next flashing sequence.
El código se supone que va a utilizar Pin C.0 como entrada botón. La entrada tiene un desplegable resistencia a la línea de 0v. El botón está conectado entre la entrada y la 5 V y una prensa de tira de la alta de entrada. He utilizado las interrupciones para capturar la pulsación de botón. La rutina utiliza dos variables de bit para asegurar que el botón se libera antes de que los cambios de rutina a la siguiente secuencia de parpadeo.
Paste the following code into the Programming Editor. I do not have a PICAXE 18M2, so have not tested it fully. If you have questions on how the code work, please ask.
Pegue el código siguiente en el Editor de programación. No tengo un PICAXE 18M2, así que no lo he probado todo. Si tiene alguna pregunta sobre cómo el código funcione, por favor pregunte.
Creo que el código se va a hacer lo que quieres.
The code assumes that you will use Pin C.0 as the button input. The input needs a pull down resistor to the 0v line. The button is connected between the input and the +5v and a press pulls the input high. I have used interrupts to capture the button press. The routine uses two bit variables to ensure that the button is released before the routine changes to the next flashing sequence.
El código se supone que va a utilizar Pin C.0 como entrada botón. La entrada tiene un desplegable resistencia a la línea de 0v. El botón está conectado entre la entrada y la 5 V y una prensa de tira de la alta de entrada. He utilizado las interrupciones para capturar la pulsación de botón. La rutina utiliza dos variables de bit para asegurar que el botón se libera antes de que los cambios de rutina a la siguiente secuencia de parpadeo.
Paste the following code into the Programming Editor. I do not have a PICAXE 18M2, so have not tested it fully. If you have questions on how the code work, please ask.
Pegue el código siguiente en el Editor de programación. No tengo un PICAXE 18M2, así que no lo he probado todo. Si tiene alguna pregunta sobre cómo el código funcione, por favor pregunte.
Code:
#PICAXE 18M2
#No_Data
'
' Hardware Pins
Symbol iButton = C.0 'Leg 17 C.0
'
' Variables 'Register b0 must not be used for other purposes
Symbol ButtonPressed = bit0 'Button was pressed
Symbol ButtonPressAndRelease = bit1 'Button was pressed and then released
Symbol bFlashProg = b1 'Flash sequence
'
' Constants
Symbol DelayBalA = 80
Symbol DelayBalB = 175
Symbol DelayBalC = 80
Symbol DelayBalD = 80
Symbol False = 25
Symbol True = 1
'
Init: SetInt %00000000,%00000001 'Interrupt when Pin C.0 is Low
'
Main: Select Case bFlashProg
Case 1
Goto bala
Case 2
Goto balb
Case 3
Goto balc
Case 4
Goto bald
EndSelect 'Other values: do nothing
GoTo Main
'
bala: For b10 = 1 To 4 'Repeat the whole sequence - 4 times
For b11 = 1 To 3 'Flash 0,1,2 - 3 times
high 0,1,2
pause DelayBalA
low 0,1,2
pause DelayBalA
Next b11
'
If ButtonPressAndRelease = True Then
ButtonPressAndRelease = False
GoTo Main
EndIf
'
For b11 = 1 To 3 'Flash 3,4,5 - 3 times
high 3,4,5
pause DelayBalA
low 3,4,5
pause DelayBalA
Next b11
'
If ButtonPressAndRelease = True Then
ButtonPressAndRelease = False
GoTo Main
EndIf
Next b10
Goto Main 'Return to the main loop
'
balb: For b11 = 1 To 9 'Flash 0 Then 5 - 8 times
high 0
pause DelayBalB
low 0
pause DelayBalB
high 5
pause DelayBalB
low 5
pause DelayBalB
'
If ButtonPressAndRelease = True Then
ButtonPressAndRelease = False
GoTo Main
EndIf
Next b11
'
For b11 = 1 To 9 'Flash 0,1 Then 4,5 - 8 times
high 0,1
pause DelayBalB
low 0,1
pause DelayBalB
high 4,5
pause DelayBalB
low 4,5
pause DelayBalB
'
If ButtonPressAndRelease = True Then
ButtonPressAndRelease = False
GoTo Main
EndIf
Next b11
'
Goto Main 'Return to the main loop
'
balc: For b10 = 1 To 8 'Repeat the whole sequence - 4 times
For b11 = 1 To 3 'Flash 0,1,2 - 3 times
high 0,1,2,4,5,6
pause DelayBalC
low 0,1,2,4,5,6
pause DelayBalC
'
If ButtonPressAndRelease = True Then
ButtonPressAndRelease = False
GoTo Main
EndIf
Next b11
'
Next b10
Goto Main 'Return to the main loop
'
bald: For b10 = 1 To 5 'Repeat the whole sequence - 4 times
For b11 = 1 To 6 'Flash 2,3 - 6 times
high 2,3
pause DelayBalD
low 2,3
pause DelayBalD
Next b11
'
If ButtonPressAndRelease = True Then
ButtonPressAndRelease = False
GoTo Main
EndIf
'
For b11 = 1 To 6 'Flash 1,4 - 6 times
high 1,4
pause DelayBalD
low 1,4
pause DelayBalD
Next b11
'
If ButtonPressAndRelease = True Then
ButtonPressAndRelease = False
GoTo Main
EndIf
'
For b11 = 1 To 6 'Flash 0,5 - 6 times
high 0,5
pause DelayBalD
low 0,5
pause DelayBalD
Next b11
'
If ButtonPressAndRelease = True Then
ButtonPressAndRelease = False
GoTo Main
EndIf
'
For b11 = 1 To 6 'Flash 1,4 - 6 times
high 1,4
pause DelayBalD
low 1,4
pause DelayBalD
Next b11
'
If ButtonPressAndRelease = True Then
ButtonPressAndRelease = False
GoTo Main
EndIf
Next b10
Goto Main 'Return to the main loop
Interrupt: If pinC.0 = 1 Then 'Button is currently pressed
ButtonPressed = True
ButtonPressAndRelease = False
SetInt %00000000,%00000001 'Next interrupt when released
Else 'Button is now released
ButtonPressed = False
ButtonPressAndRelease = True
bFlashProg = bFlashProg + 1
If bFlashProg = 5 Then
bFlashProg = 0 'Reset to 'off'
EndIf
SetInt %00000001,%00000001 'Next interrupt when pressed
EndIf
Return