I'm currently making a thermometer with 3 individual 7-segment displays, each connected to a MOSFET to cycle through them.
The problem I'm facing is that whenever I try to serial print something (for example my temperature), only one of the 3 displays is on, in this case the display with the MOSFET connected to D9.
If I don't print anything or disable Serial.begin, then all displays work.
This is the part of my code that displays digits, I'm displaying 9 as a test.
Here I'm not printing anything and all 3 displays are on.
I suspect something is taking up the full 15 milliseconds so whenever you get back to the start of loop() the elapsed time has already passed 'interval' and you go back to the first digit (Pin 9). The problem is in the part of the sketch you didn't include.
Once the output buffer is full, printing these 13 characters will take about 13 milliseconds. Perhaps changing the baud rate to 115200 will produce better results. Or you could display the temperature once per second instead of hundreds of times per second.
I've changed to code so it prints every second instead by putting the entire temperature measurement part in an If-statement that happens every 1000ms. So far all my displays work but they don't change digits, but i'll try and figure that out. Thanks a lot!
Hello,
Put the code for the leds in the main loop they don't need a restriction in time. The serial print does,
So put that in a if.
like
loop{
do the calculation;
if (millis > lasttime) {printthelot; lasttime=millis+1000;}
manupulate the leds;
}
I hope it is clear,
Yes, their switching time is faster than that of a transistor, and if the drain from your leds is <20mA you don't need them, only a resistor of about 200k. in the a-f,dp connections.
and btw
analogWrite(11, 255); ```it is anologue for digitalWrite(11,HIGH);?