Arduino: Setup () not starting

At school I am building a robot that should be able to detect lines using 3 power sensors QRE1113. (http://www.sparkfun.com/products/9454) I created 4 libraries, two for driving (Motor () and Driver ()), they work fine. Now I have created the Linesensor and Eye libraries, this causes some problems. When I want to use these libraries, the setup () function will not execute the command. Do not even turn on the LED. What is the problem?

Main file:

#include "Motor.h"
#include "Driver.h"
#include "Lichtsensor.h"
#include "Eye.h"

Motor motor1(5, 4, true);
Motor motor2(6, 7, false);
Driver driver(motor1, motor2);
Eye eye1;

void setup(){
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  Serial.begin(9600);
  Serial.println("#################################################");
  Serial.println("# This sketch communicates with the arduino and #");
  Serial.println("# makes the robot drive, and react to a sensor. #");
  Serial.println("#################################################\n");
}

void loop(){
  if (eye1.getDikkeLijn() == true) {
      Serial.println("Lijn");
    }
   else {
     Serial.println("Niks");
   }
  delay(1000);
}

Eye Library:

/*
Controls Lichtsensors
*/
#ifndef Eye_h
#define Eye_h

#include "Arduino.h"
#include "Lichtsensor.h"

class Eye 
    public:
    Eye();
    Eye(Lichtsensor l1, Lichtsensor l2, Lichtsensor l3);
    boolean getDikkeLijn();
    boolean getDunneLijn();
private:
    Lichtsensor _l1;
    Lichtsensor _l2;
    Lichtsensor _l3;
};

#endif

And the line:

/*
Library to get values from a light sensor
*/
#ifndef Lichtsensor_h
#define Lichtsensor_h

#include "Arduino.h"

class Lichtsensor {
public:
    Lichtsensor();
    Lichtsensor(int analogPin);
    int getCalibreerWaarde();
    int getLichtWaarde();
    boolean isDonker();
private:
    int _lichtCalibreerWaarde;
    int _analogPin;
};

#endif
+5
source share
3 answers

It seems that we had too many classes, and Arduino could not cope with this.

0
source

, , setup(). , , , . , .

, ( , ), , init() , . init() int my setup() Serial. - :

#include "Motor.h"
#include "Driver.h"
#include "Lichtsensor.h"
#include "Eye.h"

Motor motor1; // I do not use any more my constructor
Motor motor2; // I do not use any more my constructor
Driver driver; // I do not use any more my constructor
Eye eye1; // I do not use any more my constructor

void setup(){
    pinMode(13, OUTPUT);
    digitalWrite(13, HIGH);
    Serial.begin(9600);
    Serial.println("#################################################");
    Serial.println("# This sketch communicates with the arduino and #");
    Serial.println("# makes the robot drive, and react to a sensor. #");
    Serial.println("#################################################\n");
    motor1.init(5, 4, true); // My object is initialized here
    motor2.init(6, 7, false); // My object is initialized here
    driver.init(motor1, motor2); // My object is initialized here
    eye1.init()
}

. , , , .

, . , Eye, , Motor.

+3

I do not think that in many classes it was wrong or too many things were initialized. In my case, I have many classes defined by me (more than 5 classes). My problem was how I defined the classes, for example, one error was when I defined the function in the header file, the class name was not added in the cpp file. In code language:

void begin(); // this is a function defined in the header file
void begin(){//this is in the cpp file and this is wrong definition

} 
void NameOfTheClass::begin(){ // this is the correct way in the cpp file
   //code goes here 
}  
0
source

All Articles