Introduction
A drum sequencer helps control when drum sounds play in a pattern, making music beats repeat automatically.
Step1: Set output for drum hit 1 Step2: Wait for timer Step3: Set output for drum hit 2 Step4: Wait for timer Repeat steps for pattern
IF Timer1.Q THEN Drum1 := TRUE; Timer1.IN := FALSE; Timer2.IN := TRUE; END_IF;
IF Timer2.Q THEN Drum1 := FALSE; Drum2 := TRUE; Timer2.IN := FALSE; Timer1.IN := TRUE; END_IF;
PROGRAM DrumSequencer VAR Timer1: TON; Timer2: TON; Drum1: BOOL := FALSE; Drum2: BOOL := FALSE; Started: BOOL := FALSE; END_VAR // Initial start IF NOT Started THEN Timer1.IN := TRUE; Started := TRUE; END_IF; Timer1.PT := T#500MS; Timer2.PT := T#500MS; // Step 1: When Timer1 done, hit Drum1 IF Timer1.Q THEN Drum1 := TRUE; Drum2 := FALSE; Timer1.IN := FALSE; Timer2.IN := TRUE; END_IF; // Step 2: When Timer2 done, hit Drum2 IF Timer2.Q THEN Drum1 := FALSE; Drum2 := TRUE; Timer2.IN := FALSE; Timer1.IN := TRUE; END_IF; // Update timers Timer1(); Timer2(); END_PROGRAM
TON Timer1 (IN:=Start, PT:=T#250ms); IF Timer1.Q THEN Output1 := TRUE; ELSE Output1 := FALSE; END_IF;
TON Timer1 (IN:=Start, PT:=T#500ms); IF Timer1.Q THEN Output1 := TRUE; ELSE Output1 := TRUE; END_IF;
Pass the test and this pattern moves unknown