// MicroBoard program // Control the speed of a 5-leads unipolar stepper motor (common +ve) by // the SYSTEM and USER keys // The 4 coil leads are connected to outputs 1~4 of ULN2003, which are // controlled by Pins, 8~11, and the common lead is connected +6V #define STEP 10 // speed! smaller the number the faster the rotation main() { int i, speed; stop(); speed = 10; writes("step", 500); loop { if(!pinstate(18)) if(speed > 10) speed -= STEP; if(!pinstate(19)) if(speed < 100) speed += STEP; writei('d', speed, 50); if(speed <= 0) { stop(); continue; } for(i=8; i <= 11; i++) { pinhigh(i); delay(speed); pinlow(i); } } writes("end", 2000); } stop() { int i; for(i=8; i <= 11; i++) pinlow(i); }