函数调用是否需要表达式?

时间:2013-12-01 17:16:14

标签: c++ function arduino

在下面的代码中,我定义了一个函数“mody”,我在第78行调用。在编译时,我得到错误“在''之前的预期主表达式''令牌”。我想知道这个错误是否意味着调用一个函数我必须在一个表达式中这样做,例如“z = mody”或者什么?但我只是想去做,做它所说的并回来。或者我的电话还有其他问题吗?

    /*  BREADBOARD
  Implement program on Arduino + breadboard
*/

// constants 
int foodPin = 2;     // to provide food
int painPin = 3;     // to punish
int ucsPin = 4;      // the UCS
int csPin = 5;       // the CS
int lightPin = 6;    // turn the "light" stim on/off
int thresh = 700;

// variables 
int buttonState = 0; // variable for reading the pushbutton status
boolean lighton = false;
unsigned short int energy = 10000;
int stimulus[11] = {0,0,0,0,0,0,0,0,0,0,0};

int brain[7][11] = { {0,0,0,0,99,0,0,0,0,1,0},
                     {0,0,0,0,0,99,0,0,0,1,0},
                     {0,0,0,0,0,0,99,0,0,1,0},
                     {90,0,0,0,0,0,0,1,-1,1,-99},
                     {0,90,0,0,0,0,0,1,-1,1,1},
                     {0,0,90,0,0,0,0,1,-1,1,1},
                     {0,0,0,90,0,0,0,1,-1,1,1} };

int behavior[7] = {0,0,0,0,0,0,0};

// define behavioral methods
  void mody (int ix, int brain[][11], int stimulus[])
      { int psp=20;
        int j;
        for(j=7;j<11;j++)
    {if (brain[ix][j] > 0) brain[ix][j]+= stimulus[j] * (99-brain[ix][j])/psp;
     if (brain[ix][j] < 0) brain[ix][j]+= -1*(stimulus[j] * abs(99-brain[ix][j])/psp);}
         return;}

void setup() {
  // initialize the pushbutton pins as an input:
  pinMode(foodPin, INPUT); 
  pinMode(painPin, INPUT);
  pinMode(ucsPin, INPUT);
  pinMode(csPin, INPUT);
  pinMode(lightPin, INPUT);
  Serial.begin(9600);
  int ix=0;

} // end void setup

void loop(){
  // decay stimulus vector.  do this and check inputs for ALL stimulii later
  int k;
  for(k=0;k<11;k++)
  {if (stimulus[k] > 1) stimulus[k]-=2; else stimulus[k]=0;}

  //check inputs 
  buttonState = digitalRead(foodPin);
  if (buttonState == HIGH) stimulus[4] = 9;
  buttonState = digitalRead(painPin);
  if (buttonState == HIGH) stimulus[5] = 9;
  buttonState = digitalRead(ucsPin);
  if (buttonState == HIGH) stimulus[6] = 9;
  buttonState = digitalRead(lightPin);
  if (buttonState == HIGH) {stimulus[7] = 9; stimulus[8] = 9;lighton = true;}
      else {stimulus[7] = 0; stimulus[8] = 0;lighton = false;}
  buttonState = digitalRead(ucsPin);
  if (buttonState == HIGH) stimulus[6] = 9;

// routine to multiply:  behavior=brain * stimulus'
int i, j;
    for(i=0;i<7;i++)
    {  behavior[i]=0;
       for (j=0;j<11;j++)
           {behavior[i]= behavior[i]+stimulus[j]*brain[i][j]; }
    } // end for i
    if (behavior[0] > thresh) {Serial.println("Positive Fixer");}
    if (behavior[1] > thresh) {Serial.println("Negative Fixer");}
    if (behavior[2] > thresh) {Serial.println("UCR"); mody (2, brain[][], stimulus[]);}
    if (behavior[3] > thresh) {Serial.println("Operant one");}
    if (behavior[4] > thresh) {Serial.println("Operant two");}
    if (behavior[5] > thresh) {Serial.println("Operant three");}
    if (behavior[6] > thresh) {Serial.println("Operant four");}

// generate random operant
   if (random(energy) < 10) stimulus[random(4)]= 9 + random(3);

energy --;
Serial.println(energy);

}  // end void loop``

1 个答案:

答案 0 :(得分:3)

更改:

mody (2, brain[][], stimulus[]);

要:

mody (2, brain, stimulus);
  //        ^^^    ^^^     Get rid of []