Greetings from Germany, i had no Programming course and i already got help (from Panic Mode ) with my code but i dont know how and where to place it to get it working.
Basically i want to use this code to open and Close a Claw with the status keys (when out1 = true then the claw closes).
But i dont know the basics in KRL programming so the questions i have are:
Do i have to place the code in a .src file and if so do i have to activate that file somewhere else.
Or do i have to place these lines of code somewhere else to get it working?
I changed up thhe code a bit when there are mistakes please correct me.
Thank you in advance
Code
DEF StatusKey()
;FOLD +> Status Key detection
; check if status key is pressed
$FLAG[11]=is_key_pressed(14)
$FLAG[12]=is_key_pressed(15)
$FLAG[13]=is_key_pressed(16)
$FLAG[14]=is_key_pressed(17)
; detect rising edge of the button press
; by comparing current and remembered state
$FLAG[1] = $FLAG[11] AND NOT $FLAG[15]
$FLAG[2] = $FLAG[12] AND NOT $FLAG[16]
$FLAG[3] = $FLAG[13] AND NOT $FLAG[17]
$FLAG[4] = $FLAG[14] AND NOT $FLAG[18]
; remember previous state of the button
$FLAG[15]=$FLAG[11]
$FLAG[16]=$FLAG[12]
$FLAG[17]=$FLAG[13]
$FLAG[18]=$FLAG[14]
;ENDFOLD
;FOLD +> Status Key control
; allow status keys to control some outputs
; but only if in T1 and drives are enables
IF $T1 AND $PERI_RDY AND $USER_SAF AND NOT $PRO_ACT THEN
; for momentary state change (toggle) use flags 1..4
IF $FLAG[1] THEN
$OUT[1] = True
ENDIF
IF $FLAG[2] THEN
$OUT[2] = False
ENDIF
; for continuous outputs use flags 11..14
; $OUT[1] = $FLAG[11] ; already used for output 1
; $OUT[2] = $FLAG[12] ; already used for output 1
$OUT[3] = $FLAG[13]
$OUT[4] = $FLAG[14]
ENDIF
;ENDFOLD
END
Display More