ok nice one, i will try that after tea!You could also add
to the serial output loop, so you can see that the threshold is correct, although there is no reason why it shouldn't be.Code:Serial.print("Threshold:"); Serial.println(threshold);
thresholdMax needs to be the full scale voltage of the analogue input - i.e. 5V.am still having the issue that it only wants to trigger the output above 3.3v, which is what i set the ThresholdMax number at (max voltage the servo drive will spit out)
Yes.would that be why i am only getting whole numbers?
float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
myData.voltage = floatMap(static_cast<float>(sensor), 0, 1024, 1, 15);
Serial.printf("Reading = %d, voltage = %f\n", sensor, myData.voltage);
Just tested it and it does indeed work!!
chatgpt is fairly impressive!
yeah, im also not going to learn much by just getting chatgpt to do it for me! which i definatly want to do, as i can see these arduinos being incredibly useful for cool projects!At times. However you may find yourself going around in circles. Useful to work out where your mental block is sometimes too. Mine is/was timers using millis().
Thats a good idea, i do have a usb scope that might tell me whats happening!Could there be some sort of reset going on in there somewhere, causing a brief full voltage pulse on the line to the opto sensor? 0.5V shouldn't be enough to overcome the opto's internal LED forward voltage threshold. Might be worth looking at the line using an oscilloscope. The 0.5V might be a pulse width modulated signal, in which case smoothing it with a lowish value capacitor e.g. 1uF, might do the trick.