How to draw timing diagram from a 0 and 1 string list (2)

I like ubpdqn's last edition & Mr Wizard's refactoring to my last question very much. I inserted two Reverse just to make the diagrams and the strings match in order.

fun[str : {__String}] :=
Module[{fs, n, timd},
fs = Riffle[#, #]~Append~Last[#] & /@ ToExpression@Characters@str;
n = Length@First@fs;
timd = Reverse@fs~Append~PadLeft[{0}, n, {0, 1}];

ListLinePlot[MapIndexed[#1 + 2 First@#2 - 2 &, timd],
InterpolationOrder -> 0, Frame -> True,
FrameTicks -> {Thread[{Range[1.5, n - 1.5, 2], Range[n/2]}],
Thread[{Range[0.5, 2 Length@timd, 2],
Join[Reverse@str, {"clock"}]}], None, None},
PlotRange -> {{0, n + 1}, Automatic}]]


And here, I managed to make the input strings rotate dynamically with the following code, the problem is I failed to make the timing display rotates with the strings as well. Pls help.

str2 = {"11000011", "00000011", "11100111"};
Dynamic[
Refresh[str2 = {StringJoin[RotateRight[Characters[str2[[1]] ]]],
StringJoin[RotateRight[Characters[str2[[2]] ]]],
StringJoin[RotateRight[Characters[str2[[3]] ]]]
};
Column[{str2[[1]], str2[[2]], str2[[3]]}], UpdateInterval -> 1
],
TrackedSymbols -> {}
]

-
You may like StringRotateRight if you have V9 or later :) – kglr Jul 19 '14 at 1:23

1 Answer

First, a small change in your function fun to allow options:

funB[str : {__String}, opts : OptionsPattern[]] :=
Module[{fs, n, timd},
fs = Riffle[#, #]~Append~Last[#] & /@ ToExpression@Characters@str;
n = Length@First@fs;
timd = Reverse@fs~Append~PadLeft[{0}, n, {0, 1}];
ListLinePlot[MapIndexed[#1 + 2 First@#2 - 2 &, timd],
InterpolationOrder -> 0, Frame -> True,
FrameTicks -> {Thread[{Range[1.5, n - 1.5, 2], Range[n/2]}],
Thread[{Range[0.5, 2 Length@timd, 2],
Join[Reverse@str, {"clock"}]}], None, None},
PlotRange -> {{0, n + 1}, Automatic}, opts]]


Then, just insert funB[str2] inside Refresh:

  str2 = {"11000011", "00000011", "11100111"};

Dynamic[Refresh[str2 = StringRotateRight /@ str2;
Row[{Column[str2] // Style[#, 36] &, funB[str2, ImageSize -> 500]},
Alignment -> Center],
UpdateInterval -> 1], TrackedSymbols -> {}]


Update: You can also use Clock and use the third argument of Clock to control the number of repetitions:

 Dynamic[{Clock[{1, 1}, 2, 1]; str2 = StringRotateRight /@ str2;
Row[{Column[str2] // Style[#, 36] &, funB[str2, ImageSize -> 500]},
Alignment -> Center]}, TrackedSymbols -> {}]

-
Is there a way to stop the program? Mousedown can pause the program, "Alt+." & "Alt+," can't stop the execution. – Putterboy Jul 19 '14 at 7:20
You can toggle Dynamic Updating Enabled in the Evaluation menu. – kglr Jul 19 '14 at 23:27
Thanks a lot for your help. – Putterboy Jul 20 '14 at 3:10
@user16069, my pleasure. Welcome to mma.se. – kglr Jul 20 '14 at 3:34