LadyAda MotorTest Code

Modified to roll the motor back and forth slightly slower.

This was a geared, 12v, 100rpm motor.

MotorTest.pde
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
 
#include <AFMotor.h>
 
AF_DCMotor motor(4);
 
void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
 
  // turn on motor
  motor.setSpeed(150);
 
  motor.run(RELEASE);
}
 
void loop() {
  uint8_t i;
 
  Serial.print("tick");
 
  motor.run(FORWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i);
    delay(10);
 }
 
  for (i=255; i!=0; i--) {
    motor.setSpeed(i);
    delay(10);
 }
 
  Serial.print("tock");
 
  motor.run(BACKWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i);
    delay(10);
 }
 
  for (i=255; i!=0; i--) {
    motor.setSpeed(i);
    delay(10);
 }
 
 
  Serial.print("tech");
  motor.run(RELEASE);
  delay(1000);
}

Power consumption issues apart, how would we modify this to act according to the logic of the CMOS controller described at: Automatic Chicken Coop Door?

We need:

  1. To a pin reading 0/1 for the light level
  2. Two pins each reading 0/1 for the upper and lower door switches
  3. Logic that drives the motor forwards or backwards respectively when a 0 + 0 or a 1 + 1 condition exists
  4. We could make the motor drives into functions to keep our code clean

Discussion

Enter your comment
TMPMR
 
arduino_motor_test.txt · Last modified: 2010/07/20 12:03 by lee
Translate: AR CN DE ES FR HI PT PT-br RU UR