currentSource()

[Simulation]
void currentSource(unsigned short pin_from, unsigned short pin_to, float current, unsigned short flags = LINEAR);

Description

Creates a current source between the specified pins.

Parameters

pin_from: the Custom Element pin where the capacitance starts.

pin_to: the Custom Element pin where the capacitance ends.

current: the current value in amperes.

flags: NON_LINEAR or LINEAR to set the current source as non-linear or linear.

Returns

Nothing.

Example Code

The code creates a current source of 1A between the pins 3 and 4, and creates a non-linear current source between the pins 5 and 6 and increases the current value by 1mA every 100ms (resets at 100mA).

static unsigned long lastTime = 0;
static float current = 0.001;

void setup() {
    pinLabel(3, "IN");   // sets the pin 3 label to "IN" (input by default)
    pinLabel(4, "OUT");  // sets the pin 4 label to "OUT" (input by default)
    
    pinLabel(5, "IN");   // sets the pin 5 label to "IN" (input by default)
    pinLabel(6, "OUT");  // sets the pin 6 label to "OUT" (input by default)
    
    currentSource(3, 4, 1);  // creates a current source of 1A between the pins 3 and 4
    currentSource(5, 6, current, NON_LINEAR);  // creates a non-linear current source between the pins 5 and 6
}
void loop() {
    if (millis() - lastTime >= 100) {      // checks if the number of miliseconds is greater than 100
        lastTime = millis();
        current += 0.001;                  // increases the current value by 1mA
        if (current >= 0.1) {              // checks if the current value is greater than or equal to 100mA
            current = 0.001;
        }
        currentSource(5, 6, current);  // updates the current value between the pins 5 and 6 (the flag is not needed)
    }
}

Notes and Warnings

  • The currentSource() function can be used with all the pins, even for the power and ground pins.
  • The current value must be greater than 0 A.
  • The flags parameter is optional, if not specified, the current source will be set as linear.
  • If the current source is set as linear, it can only be set during the setup.
  • If the current source is set as non-linear, it can be changed during the setup or the loop, but needs to be initialized during the setup.
  • The currentSource() function can be used to create a current source between any two pins, and won’t change the pin mode, so be careful when using it with the pins defined as outputs.