i am doing a remember game similar to Simon Game with Twincat structured text. And i have a problem that how would i check the buttons are pressed same as the LED on, and count how many buttons have been pressed in case you press it wrong? Thanks in advance. Here is my code:
VAR
iRandomNumber: DINT;
fb_delay : ton;
Run: BOOL;
GameSpeed: TIME:= T#2S;
io.blue: bool;
io.start: bool;
END_VAR
IF IO.Start THEN
run := TRUE;
IF iRandomNumber = 1 THEN
run := FALSE;
io.Blue := TRUE;
fb_delay(in:=TRUE,PT := GameSpeed);
IF fb_delay.Q THEN
io.Blue:= FALSE;
run:= TRUE;
END_IF
END_IF
ELSIF iRandomNumber= 2 THEN
...
I do create the random number with assign to 4 leds, here is the code for 1 blue led, the rest leds are the same. The number are 1,2,3,4 and the leds are blue, green, red, yellow. The RUN var is to activate the random number generator