Arduino Test Sketch

From Calliespedia
Jump to: navigation, search

Sketch Code

/*
 * Test Program
 *
 * The basic Arduino example.  
 */

int ledPin1 = 13;                // LED connected to digital pin 13
int ledPin2 = 12;                // LED connected to digital pin 12
int motorPin1 = 9;               // Motor Controller Pin 1
int motorPin2 = 8;               // Motor Controller Pin 2


void setup()                    // run once, when the sketch starts
{
  pinMode(ledPin1, OUTPUT);      // sets the digital pin as output
  pinMode(ledPin2, OUTPUT);      // sets the digital pin as output
  pinMode(motorPin1, OUTPUT);    // sets the digital pin as output
  pinMode(motorPin2, OUTPUT);    // sets the digital pin as output
}

void loop()                     // run over and over again
{
  digitalWrite(ledPin1, HIGH);   // sets the LED on
  digitalWrite(ledPin2, LOW);    // sets the LED off
  digitalWrite(motorPin1, HIGH); // turns the motor clockwise
  digitalWrite(motorPin2, LOW);
  delay(2000);                  // waits for two seconds
  digitalWrite(ledPin1, LOW);   // sets the LED off
  digitalWrite(ledPin2, HIGH);    // sets the LED on
  digitalWrite(motorPin1, LOW);   // turns the motor counterclockwise
  digitalWrite(motorPin2, HIGH);
  delay(1000);                  // waits for a second
}