#include #include #include const int CSN = D7; const int SERVO_PIN = D0; Servo bilda_servo; const byte numChars = 32; char receivedChars[numChars]; // an array to store the received data boolean newData = false; float dataNumber = 0; // new for this version void setup() { pinMode(SERVO_PIN, OUTPUT); bilda_servo.attach(SERVO_PIN, 500, 2500); Serial.begin(19200); } void loop() { recvWithEndMarker(); float val = showNewNumber(); Serial.print("Rotation:"); Serial.print(val); Serial.print(","); Serial.print("Lower:"); Serial.print(0); Serial.print(","); Serial.print("Upper:"); Serial.println(300); float pwm_width = map(val, 0, 300, 500, 2500); bilda_servo.writeMicroseconds(pwm_width); delay(10); } void recvWithEndMarker() { static byte ndx = 0; char endMarker = '\n'; char rc; if (Serial.available() > 0) { rc = Serial.read(); if (rc != endMarker) { receivedChars[ndx] = rc; ndx++; if (ndx >= numChars) { ndx = numChars - 1; } } else { receivedChars[ndx] = '\0'; // terminate the string ndx = 0; newData = true; } } } float showNewNumber() { if (newData == true) { dataNumber = 0; // new for this version dataNumber = atof(receivedChars); // new for this version Serial.print("This just in ... "); Serial.println(receivedChars); Serial.print("Data as Number ... "); // new for this version Serial.println(dataNumber); // new for this version newData = false; } return dataNumber; }