I am new to C and Arduino. I'm sure this is a very basic oversight on my part, but so far my GoogleFoo has not yielded the solution I am looking for.
So a brief rundown of my simple project. I'm receiving serial data and using an array to determine the microsecond value to write to the servo. That function is working correctly. However, I need the servo to stay in that position until I receive a new serial value.
I would appreciate any advice you can provide.
Here is my code:
#include <Servo.h>
Servo servo1;
long num;
const int SpeedMap[211] PROGMEM = {2300, 2297, 2295, 2292, 2289, 2286, 2284, 2281, 2278, 2275, 2273, 2270, 2267, 2264, 2262, 2259, 2256, 2253, 2251, 2248, 2245, 2242, 2240, 2237, 2234, 2231, 2229, 2226, 2223, 2220, 2218, 2215, 2212, 2209, 2207, 2204, 2201, 2198, 2196, 2193, 2190, 2185, 2179, 2174, 2168, 2163, 2157, 2152, 2146, 2141, 2135, 2128, 2120, 2113, 2105, 2098, 2090, 2083, 2075, 2068, 2060, 2052, 2043, 2035, 2026, 2018, 2009, 2001, 1992, 1984, 1975, 1967, 1959, 1951, 1943, 1935, 1927, 1919, 1911, 1903, 1895, 1887, 1878, 1870, 1861, 1853, 1844, 1836, 1827, 1819, 1810, 1800, 1790, 1781, 1771, 1761, 1751, 1741, 1732, 1722, 1712, 1702, 1692, 1681, 1671, 1661, 1651, 1641, 1630, 1620, 1610, 1600, 1589, 1579, 1568, 1558, 1547, 1537, 1526, 1516, 1505, 1495, 1484, 1474, 1463, 1453, 1442, 1432, 1421, 1411, 1400, 1390, 1379, 1369, 1358, 1348, 1337, 1327, 1316, 1306, 1295, 1285, 1275, 1265, 1255, 1245, 1235, 1225, 1215, 1205, 1195, 1185, 1175, 1165, 1155, 1145, 1135, 1125, 1115, 1105, 1095, 1085, 1075, 1065, 1055, 1045, 1035, 1025, 1015, 1005, 995, 985, 975, 965, 955, 945, 935, 925, 915, 905, 895, 885, 875, 865, 855, 845, 835, 825, 815, 805, 795, 785, 774, 764, 753, 743, 732, 722, 711, 701, 690, 680, 670, 660, 650, 640, 630, 620, 610, 600, 590};
void setup()
{
servo1.attach(5, 590, 2300);
Serial.begin(9600);
Serial.print("Enter Airspeed = ");
}
void loop(){
int servMs;
int airspd;
while (Serial.available()>0) {
airspd =Serial.parseInt();
servMs=pgm_read_word(&SpeedMap[airspd]);
Serial.print(airspd);
Serial.println(" Knots");
Serial.print("Enter Airspeed = ");
}
servo1.writeMicroseconds(servMs);
delay(15);
}