Go Down

Topic: input 3 not handled during execution of procedure. With Adafruit motorcontroller (Read 25 times) previous topic - next topic

tompie

Hi,
any idea why during execution of the procedure 'void CloseEvening()' an interruption of the input 3 is not handled?
Here's my code:
Code: [Select]
#include <Time.h>
#include <TimeAlarms.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();    //motor shield on default I2C address
Adafruit_DCMotor *M = AFMS.getMotor(1);                //var M appointed to DCmotor 'port' 1

int PULSE = 2;            //switch with pulse funtionality on pin 2
int PCIN = 3;           //PhotoCell INput on pin 3
byte LASTSTATE;
unsigned long interval = 10000;
unsigned long previousMillis = 0;

void setup()
{
  AFMS.begin();            //default frequency 1.6kHz
  M -> setSpeed(100);
  pinMode(PULSE,INPUT);    //pin 2 PULSE is input
  pinMode(PCIN, INPUT);    //pin 3 PCIN is input
  Serial.begin(9600);
  LASTSTATE = 1;            //set last movement as 1
  setTime(20,18,30,2,12,14); // set time and date equal to time and date of uploading sketch
  Alarm.alarmRepeat(23,27,00, CloseEvening);  // every day
  Alarm.alarmRepeat(7,27,30, OpenMorning);  //  every day
  Serial.println("Adafruit Motorshield - automated gate henhouse");
}

void  loop(){ 
  //only used fir debugging:
  if (digitalRead(PCIN) == LOW){Serial.println("PhotoCell interrupted");}
  else{Serial.println("PhotoCell not interrupted");};
  if ((unsigned long)(millis() - previousMillis) >= interval){
  previousMillis = millis();
  digitalClockDisplay();
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
  }
  Alarm.delay(1000);     // must be used because the alarms are serviced in this method!
  //some code to be able to turn the motor left and right with one button:
  if (LASTSTATE == 1){
    while (digitalRead(PULSE) == HIGH){
      M -> run(BACKWARD);          //draai omlaag
      LASTSTATE = 0;}}
  if (LASTSTATE == 0){
    while (digitalRead(PULSE) == HIGH){
       M -> run(FORWARD);          //draai omhoog
       LASTSTATE = 1;}}
  if (digitalRead(PULSE) == LOW){
  Serial.println("motor released");  //only used for debugging
  M -> run(RELEASE);}
  }
 
// functions to be called when an alarm triggers:
void CloseEvening(){
  int PCIN = 3;
  int i = 175;
  pinMode(PCIN, INPUT);
  //Serial.println("Alarm: sluit rolluik");
  //M -> run(FORWARD);                              //selecteer draairichting
  M -> run(FORWARD);
  while (i<200 && digitalRead(PCIN) == HIGH){
  //if (digitalRead(PCIN) == LOW){
    //Serial.println("PC onderbroken");}
  //else{
    //Serial.println("PC niet onderbroken");}
  M ->setSpeed(i);
  Alarm.delay(140);
  i = i + 2;}
}

void OpenMorning(){
  int i = 168;
  Serial.println("Alarm: - open rolluik");
  M -> run(BACKWARD);
  while (i<200){
  M ->setSpeed(i);
  Alarm.delay(140);
  i = i + 2;}
}

void digitalClockDisplay()
{
  //digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  //Serial.println();
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}


Thanks for the help!

Go Up