What does the compiler tell you? Higher up the page, when I put a second definition into the file, it gave me two errors, one for the second occurrence and one pointing back at the first, and both have the file name and path and line number:
emonTxShield_CT1234_Voltage:64:11: error: redefinition of 'const int CT1'
const int CT1 = 1;
^~~
/home/r/OpenEnergy/Software/EmonTx Shield/emonTxShield_CT1234_Voltage/emonTxShield_CT1234_Voltage.ino:43:11: note: 'const int CT1' previously defined here
const int CT1 = 1;
^~~
The “C” language is case-sensitive - CT1 as an integer (used as a boolean!) and ct1 as an instance of the Energymonitor class are different. Has one got edited into the other?
Perhaps obviously, you need to search for CT1, make sure there’s no space either side in the search string.
Second possibility - have you got another file in the same directory as the source files - you should have only Shield_CT1234_Voltage.ino and emontx_lib.ino
If I put the second definition in another file:
shield_redefine_CT1:1:11: error: redefinition of 'const int CT1'
const int CT1 = 1;
^~~
/home/r/OpenEnergy/Software/EmonTx Shield/emonTxShield_CT1234_Voltage/emonTxShield_CT1234_Voltage.ino:43:11: note: 'const int CT1' previously defined here
const int CT1 = 1;
^~~
it tells me it’s on line 1, 11 characters along in the file shield_redefine_CT1.ino
If there’s another file and it’s defined in there, then because of the way the IDE has been dumbed down, it will include whatever source files it finds in the compilation, and there’s no way you can define which files it uses not the order they are used. And you’ll get the error.
If you still can’t find the second definition - the bad news is it might be in a library - though I can’t think of a good reason why it should be.
I strongly advise against platformio - if you’re using that, I can’t help you. I can only help with the Arduino IDE.
For what it’s worth, this is what my editor tells me on the original file:
Search "CT1" (12 hits in 1 file)
O:\Git\emontx-shield\firmware\Shield_CT1234_Voltage\Shield_CT1234_Voltage.ino (12 hits)
Line 57: const int CT1 = 1;
Line 70: EnergyMonitor ct1,ct2,ct3, ct4; // Create instances for each CT channel
Line 87: Serial.println("emonTX Shield CT123 Voltage example");
Line 99: if (CT1) ct1.current(1, 60.606); // Setup emonTX CT channel (ADC input, calibration)
Line 99: if (CT1) ct1.current(1, 60.606); // Setup emonTX CT channel (ADC input, calibration)
Line 104: if (CT1) ct1.voltage(0, 268.97, 1.7); // ct.voltageTX(ADC input, calibration, phase_shift) - make sure to select correct calibration for AC-AC adapter http://openenergymonitor.org/emon/modules/emontx/firmware/calibration. Default set for Ideal Power adapter
Line 104: if (CT1) ct1.voltage(0, 268.97, 1.7); // ct.voltageTX(ADC input, calibration, phase_shift) - make sure to select correct calibration for AC-AC adapter http://openenergymonitor.org/emon/modules/emontx/firmware/calibration. Default set for Ideal Power adapter
Line 120: if (CT1) {
Line 121: ct1.calcVI(20,2000); // Calculate all. No.of crossings, time-out
Line 122: emontx.power1 = ct1.realPower;
Line 126: emontx.Vrms = ct1.Vrms*100; // AC Mains rms voltage
Line 146: Serial.print(" "); Serial.print(ct1.Vrms);