Go Down

Topic: error melding (Read 210 times) previous topic - next topic

achimpieters

Hallo Allemaal!
 
Bij de onderstaande code krijg ik deze melding: invalid conversion from 'int' to 'analog_pin_t' [-fpermissive] ? :o
Kan iemand mij helpen?

Code: [Select]
//#define testrun // uncomment for test run the motor

#define LEFTSENSOR     3 // PIN 2
#define LEFTSENSORADC  3 // also PIN 2
#define LEFTMOTOR      4 // PIN 3
//#define LEFTDUTY     219 // for calibrate motor in same speed
#define RIGHTSENSOR    2 // PIN 7
#define RIGHTSENSORADC 1 // also PIN 7
#define RIGHTMOTOR     1 // PIN 6
//#define RIGHTDUTY    195 // for calibrate motor in same speed

#define THRESHOLD     56 // readings threshold for line detection
// Every analog readings from 0-1023,
// so an unsigned int allow accumulate 64 reads for average.
// Setting THRESHOLD 56 means white average * 56 / 64
// i.e. readings below 7/8 of white average means a line

unsigned int leftThreshold;
unsigned int rightThreshold;

unsigned int leftRead;
unsigned int rightRead;

bool lastTurnLeft = true;
bool firstMeetBlack = true;

void setup() {
  pinMode(LEFTMOTOR, OUTPUT);
  pinMode(RIGHTMOTOR, OUTPUT);

  delay(2000);

  readSensor(THRESHOLD);
  leftThreshold = leftRead >> 6; // divide by 64
  rightThreshold = rightRead >> 6; // divide by 64
}

void loop() {
#ifdef testrun
  turn(true, 0, 10); // minor turn left
  delay(500);
  turn(false, 0, 10); // minor turn right
  delay(500);
  turn(true, 0, 50); // turn left
  delay(500);
  turn(false, 0, 50); // turn right
  delay(500);
  turn(true, 0, 255); // full turn left
  delay(500);
  turn(false, 0, 255); // full turn right
  delay(500);
  turn(true, 10, 40); // minor dash and turn
  delay(500);
  turn(true, 30, 120); // dash and turn
  delay(500);
  turn(true, 63, 255); // full dash and turn
  delay(500);
  turn(true, 10, 0); // minor dash
  delay(500);
  turn(true, 50, 0); // dash
  delay(500);
  turn(true, 255, 0); // full dash
  delay(3000);
#else // normal run
// ========== real code start here ==========
  readSensor(4);
  leftRead >>= 2; // divide by 4
  rightRead >>= 2; // divide by 4

  bool leftBlack = (leftRead < leftThreshold);
  bool rightBlack = (rightRead < rightThreshold);

  if (firstMeetBlack && (leftBlack || rightBlack)) {
    // try to land on the line when first found it
    turn(false, 40, 160); // dash and turn
    firstMeetBlack = false;
    // todo: try to detect lost the line and set it to true again
  } else {
    if (leftBlack && rightBlack) {
      turn(lastTurnLeft, 0, 40);
    } else if (leftBlack) {
      turn(true, 0, 40);
    } else if (rightBlack) {
      turn(false, 0, 40);
    } else {
      turn(leftRead & 0b1, 0, 40); //use left readings as random run
    }
  }
  delay(40);
#endif //normal run
}

void turn(bool turnLeft, byte initTime, byte turnTime) {
  lastTurnLeft = turnLeft;

  motor(true, true);
  delay(initTime);

  motor(!turnLeft, turnLeft);
  delay(turnTime);

  motor(false, false);
}

void motor(bool leftOn, bool rightOn) {
#ifdef LEFTDUTY // PWM
  analogWrite(LEFTMOTOR, leftOn?LEFTDUTY:0);
#else
  digitalWrite(LEFTMOTOR, leftOn?HIGH:LOW);
#endif

#ifdef RIGHTDUTY // PWM
  analogWrite(RIGHTMOTOR, rightOn?RIGHTDUTY:0);
#else
  digitalWrite(RIGHTMOTOR, rightOn?HIGH:LOW);
#endif
}

void readSensor(byte count) {
  leftRead = 0;
  rightRead = 0;
  for (int i = 0; i < count; i++) {
    leftRead += analogRead(LEFTSENSORADC);
    rightRead += analogRead(RIGHTSENSORADC);
    delay(1);
  }
}



ArdLab_Gent

Bij mij geen compilatiefouten.
IDE 1.8.13, board =  Arduino UNO.
Voor welke lijn geeft de compiler deze fout?

ArdLab geeft Arduino workshops voor beginners.
ArdLab is lid van de STEM-Academie.
http://www.ardlab.gent - http://www.stem-academie.be/

Go Up