RMweb Premium melmerby Posted May 29, 2019 RMweb Premium Share Posted May 29, 2019 Hi all I've been developing a sketch using an ADAfruit 16 servo I2C board and a dcc decoder However I'm stuck with a loop not functioning as expected (right at end, everything else seems OK) I obviously have a structural error as the servo just sweeps up and down rather than up with a "HIGH" and back with a "LOW" Could someone please eye it over to see where I've gone wrong? servo_test_temp1.ino Link to post Share on other sites More sharing options...
Robin2 Posted May 30, 2019 Share Posted May 30, 2019 (edited) You are missing some {} in your IF and ELSE statements. I think it should be like this if (val == HIGH) { // if "HIGH" step servo from min to max for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen = pulselen + SERVOSTEP) { pwm.setPWM(servonum, 0, pulselen); delay (10); } } else { delay(500); //if "LOW" step servo from max to min for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen = pulselen - SERVOSTEP) { pwm.setPWM(servonum, 0, pulselen); delay (10); } } I wonder if the delay(500) is in the correct place? The Arduino Forum may be a better place for this sort of question ...R Edited May 30, 2019 by Robin2 Link to post Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now