Go Down

Topic: 'event2' was not declared in this scope (Read 472 times) previous topic - next topic

slinkymelinki

Hi there, I am trying to complete a project for school and have used some code from else where and im pretty sure it is all working but it will not upload to the actual Arduino device because of this error. Any help is appreciated

Code: [Select]
#include <CapacitiveSensor.h>
CapacitiveSensor   cs_4_5 = CapacitiveSensor(4,5);

#define TRIGGER_PIN 2
#define ECHO_PIN 3
#define USONIC_DIV 58.0
#define MEASURE_SAMPLE_DELAY 5
#define MEASURE_SAMPLES 25
#define MEASURE_DELAY 250

long timeCounter; // milliseconds counter 
long timePassed; // The actual milliseconds time
int trigPin = 2;
int echoPin = 3;
   
long delay1 = 10;    // ms for cycle of event 1 
long delay2 = 10;     // ms for cycle of event 2 
long delay3 = 10;    // ms for cycle of event 3 
long delay4 = 15;
 
// Counters for the number of triggered events before the 
// corresponding event starts 
int countEvent1, countEvent2, countEvent3, countEvent4; 
 
int TRIGGER = 5; // ms to trigger the milliseconds timer 
 
int MAX1 = 2; // Number or triggered milliseconds to start event1 
int MAX2 = 2; // Number or triggered milliseconds to start event2 
int MAX3 = 2; // Number or triggered milliseconds to start event3 
int MAX4 = 3;

// Initialisation 
void setup (void){
  Serial.begin(9600);
  pinMode(TRIGGER_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);

  digitalWrite(TRIGGER_PIN, LOW);
  delayMicroseconds(500);
   
     timeCounter = millis(); // read the actual internal time 
     timePassed = 0; // we start with no time passed 
 
     countEvent1 = 0; 
     countEvent2 = 0; 
     countEvent3 = 0;
     countEvent4 = 0;
}
 
// Infinite cycle 
void loop (void) { 
 
     // Read the actual time 
     timePassed = millis() - timeCounter; 
     // The smallest unit of time that should trigger an event is for event 2 (5 ms) 
     // so our trigger should count this smaller unit 
 
     // Check if the time passed after last reading is the trigger time 
     if(timePassed >= TRIGGER) {   
          if(++countEvent1 == MAX1){ 
               // Reset the trigger and start the event 
               event1(); 
               countEvent1 = 0; 
          } // Event 1   
           
          // It's time to manage the events 
          if(++countEvent2 == MAX2){ 
               // Reset the trigger and start the event 
               event2(); 
               countEvent2 = 0; 
          } // Event2
 
          // It's time to manage the events 
          if(++countEvent3 == MAX3){ 
               // Reset the trigger and start the event 
               event3(); 
               countEvent3 = 0; 
          } // Event3
         
          if(++countEvent4 == MAX4){ 
               // Reset the trigger and start the event 
               event4(); 
               countEvent4 = 0; 
          } // Event4
 
     } // Trigger
 
} // LOOP 
 
// ============ Event functions ==============
 
void event1(void) {
   
  long singleMeasurement()
}{
  long duration = 0;
 
  // Measure: Put up Trigger...
  digitalWrite(TRIGGER_PIN, HIGH);
  // ... wait for 11 ┬Ás ...
  delayMicroseconds(11);
  // ... put the trigger down ...
  digitalWrite(TRIGGER_PIN, LOW);
  // ... and wait for the echo ...
  duration = pulseIn(ECHO_PIN, HIGH);
  return (long) (((float) duration / USONIC_DIV) * 10.0);
  }
  long measure()
  { 
  long measureSum = 0;
  for (int i = 0; i < MEASURE_SAMPLES; i++)
  }
    delay(MEASURE_SAMPLE_DELAY);
    measureSum += singleMeasurement();
  }
  return measureSum / MEASURE_SAMPLES;
  delay(MEASURE_DELAY);
  long distance = measure();
  Serial.print(distance);
  Serial.print(",");
  }
}

void event2(void) { 
 
  long start = millis();
 
  long capTotal =  cs_4_5.capacitiveSensor(100);
 
//  Serial.print(millis() - start);        // check on performance in milliseconds

  Serial.print(capTotal);
//  Serial.print(",");
  Serial.print("\n");
                   
  delay(100);
}   
void event3(void) {   
//Serial.print("0 \n \n");

void event4(void) {
////  int Usonic = distance;
//  int sensor2 = analogRead(A1);
//  int sensor3 = analogRead(A4);
// 
//  char text [40];
//  sprintf(text, "%d,%d,%d\n", distance, sensor2, sensor3);
//  Serial.println(text);
//  delay(1);
}

AWOL

Code: [Select]
void event1(void) {
   
  long singleMeasurement()
}{

What's that?

ardy_guy

Problem starts with your curly brace pairing in event 1. Right now it thinks event1 ends here with the }:

Code: [Select]

void event1(void) {

  long singleMeasurement()
}{ //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


Delete that line and then it will end event1 at the right place here I think:

Code: [Select]

  return (long) (((float) duration / USONIC_DIV) * 10.0);
} //<<<<<<<<<<<<<<<<<<<<<<<<


But then the next function measure ends prematurely here:

Code: [Select]

long measure()
{
  long measureSum = 0;
  for (int i = 0; i < MEASURE_SAMPLES; i++)
  } //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< measure ends here
delay(MEASURE_SAMPLE_DELAY); //<<<<<<< this line is in limbo
measureSum += singleMeasurement();
}


After that I lost track.... but you need to fix those one at a time methinks.




ardy_guy

#3
Mar 25, 2017, 01:27 pm Last Edit: Mar 25, 2017, 01:28 pm by ardy_guy
im pretty sure it is all working but it will not upload to the actual Arduino device because of this error.
No it's not working: it's not compiling. It's not getting as far as trying to upload it.


Go Up