Hi,
I'm quite new with Arduino and have some issues with a project.
I need to read an array from PROGMEM, that needs to be mapped to certain range in order to control the steps of a stepper motor. Then, I need to compare the increase of the elements in the array to restrict the action of apply the steps to those elements that are equal to the last applied unless they changed.
I made spin the stepper without his library. In the function that makes the steps I have two attributes, one for the number of steps and the other for the RPM speed.
I want to replace the attribute of number of steps by the line that reads the PROGMEM array to apply the steps of that array unless the element are the same that the last one applied.
Something like this:
void loop() {
mover(50, 10); >> Instead of 50, I have to read all the elements of an array with PROGMEM
delay(200);
}
void mover (int numSteps, int rpm) {
if (numSteps >= 0) {
forward (numSteps, rpm);
} else {
backward (abs(numSteps), rpm);
}
}
It's okay if I make this?: Map the PROGMEM array and then read with pgm_read the variable now defined?
pwm_map = map(pwm1, 99, 3690, 10, 500); //pwm1 is the original PROGMEM Array
pgm_read_word_near(pwm_map + n); //reading the mapped PROGMEM array now defined as pwm_map
Then it's okay if I write something like this?: I'm confusing the increase with the for cycle and the pgm_read...
for (int = 0; i < lenghtArray; i++) { //Will work the condition if I don't execute the pgm_read here also?
mover(pgm_read_word_near(pwm_map), 10); //Do I need to put the n++ after this sentence?
if (pgm_read_word_near(pwm_map) == n { // Here I need to compare the present element to the last one
I'm kind of confused with the read and increase thing.
Sorry for the little mess!
Thank you so much!