Hardware Reference
In-Depth Information
else
{
Serial.println("Failed to read from sensor");
}
}
In the reset_stepper() function, we will execute the stepper motor's
clockwise routine until the object is detected. The sensor reference manual
mentions that an object is detected if the second LSB is set to low. Hence,
the stepper rotates in the clockwise direction until a low signal is detected.
Programming the weather forecast position
1.
In the previous secion, we discussed the stepper motor control via the serial port.
Since we are using a stepper motor, it is possible to point at each weather forecast
condiion based on a predetermined number of steps from the step. So, we will
determine the number of steps required to point at each weather forecast condiion
and program these posiions into the lash memory of the Arduino.
We should use the PROGMEM keyword to store the position data in the
flash memory of the Arduino since they are a constant:
const int mydata[6][2] PROGMEM = {
1, 10,
2, 18,
3, 28,
4, 43,
5, 54,
6, 66};
The numbers 1 through 6 in the array correspond to the weather forecast
indicators starting in the counterclockwise direction. The second position
indicates the number of positions from the home position to point to that
particular weather condition.
The command for indicating weather data is preceded by the letter T . In
order to point to the weather forecast, Rain , the command would be T-6 .
When a character T is received, we store the data received in a buffer. It is
confirmed that the second character received after the letter T is a number
between 1 and 6 . We will retrieve the corresponding position data from the
flash memory using the pgm_read_word_near() function. Once the data
is retrieved, the stepper motor control routine is executed for the desired
number of steps.
 
Search WWH ::




Custom Search