Hi, I'm building a temperature monitor with the ability to switch relays depending on logic generated in node red, my first iteration had lots of repeated code setting each pin to do a function but I've since changed it so i can set any pin to either read temperature from ds18b20 or turn a relay on or off. i was wondering if my code could create memory issues once its in full time use with how its structured, all is working in the short time I've tested it.
Code included below, serial process was copied from another post a while ago for dealing with start and stop characters.
My code is working fine when I call or they turns on or off. Also when I call returns the the temperature for each ds18b20 on that pin via serial which I read and process in node red, what do you mean it will only work on single digit pins.
My plan was to hard code any pins so once I start wiring I can use any digital pin for either temperature or relay control.
I had it working hard coded and the code was so repetitive it was bothering my and I thought I could improve it. Each temperature pin will have 3x ds18b20 these will be in zone and I will average these out incase one is a little out it should stabilise my readings. Then I will turn a relay on with a heater connected. This is a fish room control system.
My worry about the code was that creating DallasTemperature objects on the fly and then possibly using the same pin later as a relay pin code cause some memory issues. I will look at your code and try to understand your improvements after work.
I definitely see the improvement with the if statements. And I see what you mean about the substring and single digits but I've been using pins 22 - 53 with no issues.
If you have concerns about memory, grab a copy of a freemem or freememory function - Adafruit has one. It'll let you see if you have a leak. Given that you're using String objects in a number of areas of your code, I won't be surprised if you do.
Thanks I will look at checking memory usage. And possibly try and eliminate string functions from my code if I can. The system isn't mission critical but I'm trying to improve, I'm a novice programmer, I can get things to work in a few languages but don't actually know them fluently enough to know what I'm doing wrong or what's a better way.