I'm new to the Arduino and real-time/real-world code in general. I'm enjoying coding for a modestly complex Arduino application. I've never done much in C, but until I face arcane issues of one kind or another I'm finding it simple enough.
I'm also relatively unschooled in object oriented programming, though I understand the basics and have coded some here and there over the years. My current project could definitely benefit from object coding, but a real-time issue is leaving me puzzled.
I need to gradually brighten a lamp using PWM on cue; e.g., when a particular input condition is met, capture current millis() in a timer variable, and use MAP to get an 8 bit level for the PWM from the brightening duration. At least that's what I'm doing and it works simply and quite well.
But having a lot of lamps for which this must be done suggests -- to my noob mind, anyway -- that it'd be less hassle to instance an object for each lamp, with a brighten method in play.
Question: how the heck could a "brighten" method in a lamp object work during each iteration of the main loop to change the PWM incrementally on each pass? Passing to the method a duration of brightening, a beginning level and an end level, for example (400, 0, 255) -- well, I can't imagine how it would work.
It'd be nice of the Arduino would multithread. ;)
Anyone have any ideas for this? It's possible I'm entirely missing something obvious, but for the life of me I can't figure this out.
Just now I have a "brighten" function I call from a "lamps" function, which moves most individual lamp code out of loop, of course, but very little out of the "lamps" function. The timers and everything really clutter that up. The lamps function basically just takes which lamp to act on, what timer variable corresponds to it, and then it does the brightening using a MAP statement.
I just don't think it can all be in the object. Am I right?