0

i already have my code and if i am wrong please correct me. But the code isnt my problem ... i dont know where and how i use it in the KRC4 interface i thought a .src file would be enough inside of the KRC -> R1 -> System Folder ... but guess what it does not work like that. I never had a programming course in KRL so i am missing a basic step to use my code. 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[1] = 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

1 Answers1

0

You need to put this in a *.sub for it to evaluate cyclically. You can also just call statuskey() from a submit in case you do not want to move the code.

Keep in mind to never put waits or similar in sps.sub

HES
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 03 '22 at 17:08
  • Like HES said call the programm from the sps.sub (submit-Interpreter) and it will be fine. Some tips: use functions for detecting rise edge and press a button, variables and not flags, maybe some constants, structures, eliminate or minimize comments... – Daniel Müller Navarro Aug 17 '22 at 08:27