我已经创建了带有线路和设备的 I2C 总线框图(但我认为我的方法很差...我在网上查过并没有找到任何用 latex 绘制 I2C 协议的示例):
\documentclass[xcolor=x11names,compress]{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}{I$^{2}$C}
\begin{tikzpicture}
% \draw[gray] (0,0) grid (11,3);
% \foreach \x in {0,1,...,11}
% \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
% \foreach \y in {1,2,3}
% \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
%draw master and slave device
\draw [rounded corners, fill=blue!30] (0, 1.5) rectangle (2.5,3) node[pos=.5] {I$^{2}$C Master};
\foreach \x in {3,6,9}
{
\draw [rounded corners, fill=orange] (\x, 0) rectangle (\x+2,1) node[pos=.5] {I$^{2}$C Slave};
}
%draw circuit
\draw[very thick] (2.5,1.8) -- (11,1.8) node[pos=1, below] {$SCL$}; %SCL
\draw[very thick] (2.5,2.7) -- (11,2.7) node[pos=1, above] {$SDA$}; %SDA
\foreach \x in {3.5, 6.5, 9.5}
{
\draw (\x, 1) -- (\x, 1.8);
\node at (\x, 1.8) {\textbullet};
}
\foreach \x in {4.5, 7.5, 10.5}
{
\draw (\x, 1) -- (\x, 2.7);
\node at (\x, 2.7) {\textbullet};
}
\end{tikzpicture}
\end{frame}
\end{document}
我不知道是否有任何包可以绘制I2C?我的想法是始终绘制一个网络:
\begin{tikzpicture}
\draw[gray] (0,0) grid (11,3);
\foreach \x in {0,1,...,11}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {1,2,3}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\end{tikzpicture}
并开始在这个网上画画。
谁能帮助我优化我的代码并轻松绘制这个 I2C 总线和设备?
此外,我想要遵循 I2C 协议绘制,有人可以给我一个起点吗?
或者这个看起来很简单?
答案1
nodes
您可以利用图书馆的帮助,使用已经绘制好的网格作为参考,而不必使用网格作为参考positioning
。
不要使用rectangles
+,而要text
使用drawn
和filled
节点。
最后,使用节点锚点和交叉点坐标来定位或定义其他元素。
\documentclass[xcolor=x11names,compress]{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{frame}[fragile]{I\textsuperscript{2}C}
\begin{tikzpicture}[master/.style={draw, rounded corners, fill=blue!30, minimum height=15mm, minimum width=2.5cm},
slave/.style={draw, rounded corners, fill=orange, minimum height=10mm, minimum width=2cm}]
\node[master] (m) {I\textsuperscript{2}C Master};
\node[slave, below right=3mm and 7mm of m] (s1) {I\textsuperscript{2}C Slave};
\node[slave, right= 6mm of s1] (s2) {I\textsuperscript{2}C Slave};
\node[slave, right= 6mm of s2] (s3) {I\textsuperscript{2}C Slave};
\draw[thick] (m.15)--(m.15-|s3.east) node[above]{SDA};
\draw[thick] (m.-15)--(m.-15-|s3.east)node[below]{SCL};
\foreach \i in {1,2,3}{
\draw[fill=black] (s\i.55)--(s\i.55|-m.15) circle (2pt);
\draw[fill=black] (s\i.115)--(s\i.115|-m.-15) circle (2pt);
}
\end{tikzpicture}
\end{frame}
\end{document}