# How can I use system's own clock while setting input?

**URL:** <https://brian.discourse.group/t/how-can-i-use-systems-own-clock-while-setting-input/988>\
**Category:** Support\
**Created:** [8 May 2023 17:05 UTC](https://brian.discourse.group/t/how-can-i-use-systems-own-clock-while-setting-input/988 "2023-05-08T17:05:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SirK](https://avatars.discourse-cdn.com/v4/letter/s/74df32/32.png) [@SirK](https://brian.discourse.group/u/SirK)\
**Post date:** [8 May 2023 17:05 UTC](https://brian.discourse.group/t/how-can-i-use-systems-own-clock-while-setting-input/988/1 "2023-05-08T17:05:05Z")

</div>

# Description of problem

Hey everyone  
I have some experience about coding and building networks but I am new in Brian and brianforum. I’m trying to create a model and I am wanting to use my old input formula because my input should change continuously over time within a certain rule but it seems like I cannot convert that into brianish 🙂  
There is a basic example of my code. The “t” in example should be the time that used in the operation of the system.  
I would be very grateful if someone could help me with that. Thanks !

# Minimal code to reproduce problem

```python
def input_pulse():
    if t<td1 :
        return B0
    elif (t >= td1 and t < td2):
        if (t < (td1+tp)):
            return B1
        else:
            return B0
    elif (t>=td2 and t<(td2+tp)):
          return B2
    else:
        return B0

```

---

<div class="post-metadata">

**Author:** ![rth](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/rth/32/16_2.png) [@rth](https://brian.discourse.group/u/rth)\
**Post date:** [8 May 2023 21:06 UTC](https://brian.discourse.group/t/how-can-i-use-systems-own-clock-while-setting-input/988/2 "2023-05-08T21:06:21Z")

</div>

Hi @SirK , welcome to the Brian’s friends club 🙂

So there are a several ways to implement something like that:

1. You can use [TimedArray](https://brian2.readthedocs.io/en/stable/user/input.html#timed-arrays) if `td1`, `td2`, `td1+tp`, and `td2+tp` are constant and can be round to an integer of some `dt`. This is a very fast and convenient method to create a stimulus, but it something requires too much memory 😉.
2. If you have a few condition you can implement them as logic expression in the equation for your neurons (see [here](https://brian2.readthedocs.io/en/stable/advanced/functions.html#default-functions)). Something like that `B0 + (B1-B0)*int( (t>=td1)*(t<(td1+tp)) +(B2-B0)*int( (t>=td2)*(t<(td2+tp)))`. This is also pretty fast.
3. Finally you can use [user-provided function](https://brian2.readthedocs.io/en/stable/advanced/functions.html#user-provided-functions) which usually slow if written in Python. So this isn’t a best option unless you code it up in Cython or C.

Hope this helps

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [9 May 2023 09:37 UTC](https://brian.discourse.group/t/how-can-i-use-systems-own-clock-while-setting-input/988/3 "2023-05-09T09:37:39Z")

</div>

Let me add one more option: you can use multiple run statements and change the stimulus strength in between. Somethin along the lines of:

```python
neurons = NeuronGroup(..., '''dv/dt = ... + I ...''', ...)
I = B0
run(...)
I = B1
run(...)
I = B0
run(...)
I = B2
run(...)
I = B0
run(...)

```

PS: a minor formatting thing: try to put Python code between triple backticks for nicer display:

````auto
```
# Here comes the Python code
print('something')
```

````

---

<div class="post-metadata">

**Author:** ![SirK](https://avatars.discourse-cdn.com/v4/letter/s/74df32/32.png) [@SirK](https://brian.discourse.group/u/SirK)\
**Post date:** [9 May 2023 13:58 UTC](https://brian.discourse.group/t/how-can-i-use-systems-own-clock-while-setting-input/988/4 "2023-05-09T13:58:39Z")

</div>

Thank you so much for your kind responds. It seems like TimedArray will solve my problem 👍
