I have a teaching experiment in electronics on Monday that involves flashing a microcontroller controlling a H-bridge in turn connected to a DC motor. I need to write code for it in C, and I'd like to get most of it done before the actual experiment, so I'm doing it now. Or at least trying to. I wouldn't be surprised my code is riddled with syntax errors, inconsistencies and missing functions.
Most of the programs I've written so far have been fairly simple, so not much can go wrong, and even if it has, it's easy to correct. I'm having a lot of trouble with the final one, though. I have to write a timed sequence that varies the voltage, and hence the motor speed. Here's the sequence:

(hope it's not too much copyright infringement to post it here...)
Nevermind the x and y, we'll be given those values during the experiment.
I'm trying to do this with for functions with an integer variable called "time", with 1 second increments. The vertical axis is the motor speed, but that's controleld by the voltage, so the object variable of the for functions can be either:
1. voltage "volt", a floating variable that can adopt any value from 0 to 5
2. "duty_cycle", an integer variable, basically a percentage of the voltage.
I reckon the easiest would be to use "duty_cycle", as it's an integer variable. But as I said, I'm not sure how the function works. Can I include the entire sequence in a single function? Is it better to use a while function or switch/case.
However, the increase (or decrease) in motor speed is, judging from the sequence, linear and continuous, which I interpret as best described by a floating variable. I'm also not sure how to have the objective variable vary continuously with a 1 increment increase in time.
I don't expect anyone to solve it (nor do I want anyone to), as there's a lot of information missing, but I'd appreciate any hint or suggestion. This is the first time ever I'm programming, and I started this morning.
Most of the programs I've written so far have been fairly simple, so not much can go wrong, and even if it has, it's easy to correct. I'm having a lot of trouble with the final one, though. I have to write a timed sequence that varies the voltage, and hence the motor speed. Here's the sequence:

(hope it's not too much copyright infringement to post it here...)
Nevermind the x and y, we'll be given those values during the experiment.
I'm trying to do this with for functions with an integer variable called "time", with 1 second increments. The vertical axis is the motor speed, but that's controleld by the voltage, so the object variable of the for functions can be either:
1. voltage "volt", a floating variable that can adopt any value from 0 to 5
2. "duty_cycle", an integer variable, basically a percentage of the voltage.
I reckon the easiest would be to use "duty_cycle", as it's an integer variable. But as I said, I'm not sure how the function works. Can I include the entire sequence in a single function? Is it better to use a while function or switch/case.
However, the increase (or decrease) in motor speed is, judging from the sequence, linear and continuous, which I interpret as best described by a floating variable. I'm also not sure how to have the objective variable vary continuously with a 1 increment increase in time.
I don't expect anyone to solve it (nor do I want anyone to), as there's a lot of information missing, but I'd appreciate any hint or suggestion. This is the first time ever I'm programming, and I started this morning.