Hardware Reference
In-Depth Information
function sweep () {
pos += step ; // Take a step
if ( pos > max || pos < min ) {
step *= - 1 ;
}
move ( pos );
}
function move ( pos ) {
var dutyCycle = pos / 1000 * freq ;
b . analogWrite ( motor , dutyCycle , freq );
console . log ( 'pos = ' + pos + ' duty cycle = ' + dutyCycle );
}
process . on ( 'SIGINT' , function () {
console . log ( 'Got SIGINT, turning motor off' );
clearInterval ( timer );
// Stop the timer
b . analogWrite ( motor , 0 , freq );
// Turn motor off
});
Running the code causes the motor to move back and forth, progressing to successive pos-
itions between the two extremes. You will need to press ^C (Ctrl-C) to stop the script.
Search WWH ::




Custom Search