## Example for N Bit Johnson Counter.

``````

In [1]:

# imports

from __future__ import print_function
from BinPy.tools import Clock
from BinPy.sequential.counters import JohnsonCounter
from BinPy.gates import Connector

``````
``````

In [2]:

# Initializing the Clock
# A clock of 50 hertz frequency

clock = Clock(1, 50)

``````
``````

In [3]:

# Initialize enable

enable = Connector(1)

# Initializing the counter

# Initializing Johnson with 8 bits and clock

b = JohnsonCounter(8, clock)

# Initial State

print (b.state())

``````
``````

[]

``````
``````

In [4]:

# Triggering the counter 24 times

for i in range(24):
b.trigger()
print (b.state())

# Calling the instance will trigger

b()

print(b.state())

``````
``````

[1, 1, 0, 0, 0, 0, 0, 0]
[1, 1, 1, 0, 0, 0, 0, 0]
[1, 1, 1, 1, 0, 0, 0, 0]
[1, 1, 1, 1, 1, 0, 0, 0]
[1, 1, 1, 1, 1, 1, 0, 0]
[1, 1, 1, 1, 1, 1, 1, 0]
[1, 1, 1, 1, 1, 1, 1, 1]
[0, 1, 1, 1, 1, 1, 1, 1]
[0, 0, 1, 1, 1, 1, 1, 1]
[0, 0, 0, 1, 1, 1, 1, 1]
[0, 0, 0, 0, 1, 1, 1, 1]
[0, 0, 0, 0, 0, 1, 1, 1]
[0, 0, 0, 0, 0, 0, 1, 1]
[0, 0, 0, 0, 0, 0, 0, 1]
[0, 0, 0, 0, 0, 0, 0, 0]
[1, 0, 0, 0, 0, 0, 0, 0]
[1, 1, 0, 0, 0, 0, 0, 0]
[1, 1, 1, 0, 0, 0, 0, 0]
[1, 1, 1, 1, 0, 0, 0, 0]
[1, 1, 1, 1, 1, 0, 0, 0]
[1, 1, 1, 1, 1, 1, 0, 0]
[1, 1, 1, 1, 1, 1, 1, 0]
[1, 1, 1, 1, 1, 1, 1, 1]
[0, 1, 1, 1, 1, 1, 1, 1]
[0, 0, 1, 1, 1, 1, 1, 1]

``````