Wrote this and it works but is jittery, I guess because the processor is busy doing other things like Tom said. What's the reason for not wanting to use the lib?
uint32_t uStime, cycle = 2500, pTime = 1476;
void setup() {
// initialize serial:
Serial.begin(9600); //set serial monitor baud rate to match
pinMode(9,OUTPUT);
}
void loop()
{
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int pos = Serial.parseInt();
pos = constrain(pos, 544, 2400);
pTime = (pos);
Serial.println(pTime);
}
bitWrite(PORTB,1,micros() - uStime < pTime);
if(micros() - uStime > cycle)
uStime += cycle;
}