loop()
[Main Functions]
void loop();Description
The loop() function is called repeatedly by the
simulation engine. It loops continuously, allowing your program to
change the state of the pins, respond to external signals, and draw on
the chip. Use it to implement the logic of your custom element.
Parameters
None.
Returns
Nothing.
Example Code
void setup() {
// Set the chip name "74LS04" (Hex inverting gates)
chipName("74LS04");
logicFamily(TTL); // Specify TTL logic family
// Define left side input and output pins
pinLabel(1, "1A");
pinLabel(2, "Y1");
pinMode(2, OUTPUT);
pinLabel(3, "2A");
pinLabel(4, "Y2");
pinMode(4, OUTPUT);
pinLabel(5, "3A");
pinLabel(6, "Y3");
pinMode(6, OUTPUT);
// Define the ground pin
pinLabel(7, "GND");
groundPin(7);
// Define the right side input and output pins
pinLabel(8, "Y4");
pinMode(8, OUTPUT);
pinLabel(9, "4A");
pinLabel(10, "Y5");
pinMode(10, OUTPUT);
pinLabel(11, "5A");
pinLabel(12, "Y6");
pinMode(12, OUTPUT);
pinLabel(13, "6A");
// Define the power pin
pinLabel(14, "VCC");
powerPin(14);
}
void loop() {
// Write the negation of the first input pin to the first output pin
bool a1 = digitalRead( 1);
digitalWrite(2, !a1);
// Write the negation of the second input pin to the second output pin
bool a2 = digitalRead( 3);
digitalWrite(4, !a2);
// Write the negation of the third input pin to the third output pin
bool a3 = digitalRead( 5);
digitalWrite(6, !a3);
// Write the negation of the fourth input pin to the fourth output pin
bool a4 = digitalRead( 9);
digitalWrite(8, !a4);
// Write the negation of the fifth input pin to the fifth output pin
bool a5 = digitalRead( 11);
digitalWrite(10, !a5);
// Write the negation of the sixth input pin to the sixth output pin
bool a6 = digitalRead( 13);
digitalWrite(12, !a6);
}Notes and Warnings
Adding drawing code inside the loop function will lead to a flickering effect.
