Error message appearing even though LED is connected properly
rinon13 opened this issue · comments
Description: A pop up error message "LED is not Connected properly" is showing on right hand side of screen even though LED is connected properly.
Steps to Reproduce:
- Connect circuit as shown above.
- Copy .ino code
int POS_PIN = 13;
int NEG_PIN = 12;
void setup(){
pinMode(POS_PIN, OUTPUT);
pinMode(NEG_PIN, OUTPUT);
digitalWrite(NEG_PIN, LOW);
}
void loop(){
digitalWrite(POS_PIN, HIGH);
delay(500);
digitalWrite(POS_PIN, LOW);
delay(500);
}
- Press "Start Simulation"
- Error message will appear on top right of screen
Expected behavior: Error message should not appear when LED is connected to digital pins which are programmed correctly (.ino code is written correctly) i.e POSITIVE pin is given HIGH and NEGATIVE pin is given LOW
Error example:
- OS: Ubuntu 22.04.1 LTS
- Browser: Firefox 110
Tested on:
- simulation.iitbx.in
- develop
- https://github.com/rinon13/eSim-Cloud/tree/LED_Pin_Connection_Issue (Fixed issue where both NEGATIVE and POSITIVE pins of LED are not working when connected to Digital Pins of Arduino)
Reason for error:
- When "Start Simulation" is pressed, LED's simulation function is called before Arduino's simulation function.
(LED is of type output)
(Code at eSim-Cloud/ArduinoFrontend/src/app/Libs/Workspace.ts) (Line 1045)
// Sequence to be followed while calling initSimulation
const seqn = ['output', 'general', 'controllers', 'drivers', 'power', 'input', 'misc'];
// For each component call initsimulation function
for (const key of seqn) {
for (const items of Utils.componentBox[key]) {
for (const item of items) {
if (window.scope[item]) {
for (const ele of window.scope[item]) {
if (ele.initSimulation) {
ele.initSimulation();
}
}
}
}
}
}
- When LED tries to read the values of connected Arduino pins, they have not been initialized yet.
- This causes the checks to see if LED is connected properly to not be satisfied.
Additional information:
The error message only stays for a short while and will go away after the values of the Arduino pins have been initialized.
Fixed in #467