Skip to content

Instantly share code, notes, and snippets.

@JamesSwift
Created November 15, 2013 22:37
Show Gist options
  • Save JamesSwift/7492869 to your computer and use it in GitHub Desktop.
Save JamesSwift/7492869 to your computer and use it in GitHub Desktop.

Revisions

  1. @James-swift James-swift created this gist Nov 15, 2013.
    41 changes: 41 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #define FULL_POWER_OFFSET 3


    task main()
    {
    SetSensor(SENSOR_2,SENSOR_LIGHT);
    int last_reading=SENSOR_2;

    //start adjust_power;
    SetPower(OUT_A+OUT_C,7);

    while (true) {
    if (SENSOR_2 > last_reading){
    OnFwd(OUT_A+OUT_C);
    Wait(0);
    if (SENSOR_2-last_reading>FULL_POWER_OFFSET){
    //OnFwd(OUT_A+OUT_C);
    until(SENSOR_2<=last_reading+FULL_POWER_OFFSET);
    OnRev(OUT_C+OUT_A);
    Wait(0);
    Off(OUT_A+OUT_C);
    }
    Off(OUT_A+OUT_C);
    Wait(0);
    }
    if (SENSOR_2 < last_reading){
    OnRev(OUT_C+OUT_A);
    Wait(0);
    if (last_reading-SENSOR_2>FULL_POWER_OFFSET){
    //OnRev(OUT_C+OUT_A);
    until(SENSOR_2>=last_reading-FULL_POWER_OFFSET);
    OnFwd(OUT_C+OUT_A);
    Wait(0);
    Off(OUT_A+OUT_C);
    }
    Off(OUT_A+OUT_C);
    Wait(0);
    }

    }
    }