Klein Bot

Kleins, robots, electricity

Blog

Larson (Cylon) Scanner

Posted by Klein on March 2, 2013 at 4:40 PM

Here is the first working code that the kids produced for the Larson, a.k.a. Cylon, scanner for their FIRST competition robot.


int timeBetween = 100;

int millisCounter = 0;

int delayTime = 0;

int activePin = 0;

 

void setup() {

  // put your setup code here, to run once:

  pinMode(0, OUTPUT);

  pinMode(1, OUTPUT);

  pinMode(2, OUTPUT);

  pinMode(3, OUTPUT);

  pinMode(4, OUTPUT);

  pinMode(5, OUTPUT);

  pinMode(6, OUTPUT);

  pinMode(7, OUTPUT);

  pinMode(8, OUTPUT);

  pinMode(9, OUTPUT);

  pinMode(10, OUTPUT);

  pinMode(11, OUTPUT);

  pinMode(12, OUTPUT);

 

}

 

void loop() {

  // put your main code here, to run repeatedly:

  millisCounter = millis();

//  delayTime = (millisCounter / timeBetween);

 

//  activePin = (millisCounter / 100)% 22;

//  if (activePin >= 11) {

//    activePin = activePin - 11;

    

//  }

 

  switch (activePin) {

    case 0:

      pinOn(0, 400);

      pinOn(11, 300);

      break;

    case 1:

      pinOn(1, 500);

      pinOn(0, 400);

      break;

    case 2:

      pinOn(2, 600);

      pinOn(1, 500);

      break;

    case 3:

      pinOn(3, 700);

      pinOn(2, 600);

      break;

    case 4:

      pinOn(4, 800);

      pinOn(3, 700);

      break;

    case 5:

      pinOn(5, 900);

      pinOn(4, 800);

      break;

    case 6:

      pinOn(6, 900);

      pinOn(5, 800);

      break;

    case 7:

      pinOn(7, 800);

      pinOn(6, 700);

      break;

    case 8:

      pinOn(8, 700);

      pinOn(7, 600);

      break;

    case 9:

      pinOn(9, 600);

      pinOn(8, 500);

      break;

    case 10:

      pinOn(10, 500);

      pinOn(9, 400);

      break;

    case 11:

      pinOn(11, 400);

      pinOn(10, 300);

      break;

    case 12:

      pinOn(10, 500);

      pinOn(11, 400);

      break;

    case 13:

      pinOn(9, 600);

      pinOn(10, 500);

      break;

    case 14:

      pinOn(8, 700);

      pinOn(9, 600);

      break;

    case 15:

      pinOn(7, 800);

      pinOn(8, 700);

      break;

    case 16:

      pinOn(6, 900);

      pinOn(7, 800);

      break;

    case 17:

      pinOn(5, 900);

      pinOn(6, 800);

      break;

    case 18:

      pinOn(4, 800);

      pinOn(5, 700);

      break;

    case 19:

      pinOn(3, 700);

      pinOn(4, 600);

      break;

    case 20:

      pinOn(2, 600);

      pinOn(3, 500);

      break;

    case 21:

      pinOn(1, 500);

      pinOn(2, 400);

      break;

    

  }

 

  activePin += 1;

 

  if (activePin == 22) {

    activePin = 0;

  }

 

//  delay(50);

 

}

 

void pinOn(int pin, int pwr) {

  digitalWrite(pin, HIGH);

  delay(pwr/10);

  digitalWrite(pin, LOW);

  delayMicroseconds(1000-pwr);

 

 

}


Categories: FIRST Robotics

Post a Comment

Oops!

Oops, you forgot something.

Oops!

The words you entered did not match the given text. Please try again.

Already a member? Sign In

0 Comments