examples/line-follower.js
function(){
  scheduler.sequence(function(){
    console.log("running");
      
    motors.set({"A,B": 20, "C,D": 0}); //move left wheels
      
  }).wait(function(){

    //wait until we moved off the line
    return colorSensor.value == ColorSensor.colors.WHITE;
    
  }).do(function(){

      motors.set({"A,B": 0, "C,D": 20}); //move right wheels

  }).wait(function(){

    //wait until we're back on the line

    if(colorSensor.value == ColorSensor.colors.BLUE) console.log("blue now");
    return colorSensor.value == ColorSensor.colors.BLUE;

  }).wait(function(){
    
    //now wait until we're off the line
    if(colorSensor.value == ColorSensor.colors.WHITE) console.log("now white");
    return colorSensor.value == ColorSensor.colors.WHITE;

  }).do(function(){

    motors.set({"A,B": 20, "C,D": 0}); //move left wheels

  }).wait(function(){

    //wait until we're back on the line
    return colorSensor.value == ColorSensor.colors.BLUE;

  }).do(function(){

    console.log("rescheduling");
    this.schedule(); //reschedule the sequence now that we're back at the starting conditions
    
  }).schedule(); //schedule the sequence to be run
}
function(){
  scheduler.sequence(function(){
    console.log("running");
      
    motors.set({"A,B": 20, "C,D": 0}); //move left wheels
      
  }).wait(function(){

    //wait until we moved off the line
    return colorSensor.value == ColorSensor.colors.WHITE;
    
  }).do(function(){

      motors.set({"A,B": 0, "C,D": 20}); //move right wheels

  }).wait(function(){

    //wait until we're back on the line

    if(colorSensor.value == ColorSensor.colors.BLUE) console.log("blue now");
    return colorSensor.value == ColorSensor.colors.BLUE;

  }).wait(function(){
    
    //now wait until we're off the line
    if(colorSensor.value == ColorSensor.colors.WHITE) console.log("now white");
    return colorSensor.value == ColorSensor.colors.WHITE;

  }).do(function(){

    motors.set({"A,B": 20, "C,D": 0}); //move left wheels

  }).wait(function(){

    //wait until we're back on the line
    return colorSensor.value == ColorSensor.colors.BLUE;

  }).do(function(){

    console.log("rescheduling");
    this.schedule(); //reschedule the sequence now that we're back at the starting conditions
    
  }).schedule(); //schedule the sequence to be run
}
function ( ) { scheduler . sequence ( function ( ) { console . log ( "running" ) ; motors . set ( { "A,B" : 20 , "C,D" : 0 } ) ; //move left wheels } ) . wait ( function ( ) { //wait until we moved off the line return colorSensor . value == ColorSensor . colors . WHITE ; } ) . do ( function ( ) { motors . set ( { "A,B" : 0 , "C,D" : 20 } ) ; //move right wheels } ) . wait ( function ( ) { //wait until we're back on the line if ( colorSensor . value == ColorSensor . colors . BLUE ) console . log ( "blue now" ) ; return colorSensor . value == ColorSensor . colors . BLUE ; } ) . wait ( function ( ) { //now wait until we're off the line if ( colorSensor . value == ColorSensor . colors . WHITE ) console . log ( "now white" ) ; return colorSensor . value == ColorSensor . colors . WHITE ; } ) . do ( function ( ) { motors . set ( { "A,B" : 20 , "C,D" : 0 } ) ; //move left wheels } ) . wait ( function ( ) { //wait until we're back on the line return colorSensor . value == ColorSensor . colors . BLUE ; } ) . do ( function ( ) { console . log ( "rescheduling" ) ; this . schedule ( ) ; //reschedule the sequence now that we're back at the starting conditions } ) . schedule ( ) ; //schedule the sequence to be run }
this assumes we're following a blue line on a white background also assumes there is a wall at the end of the line we're following
this assumes we re following a blue line on a white background also assumes there is a wall at the end of the line we re following