user32143: Was trying to work some code that I found online to suit my needs and it continues to show the same error 'setup' does not name a type. I have tried setting it to void, Void as well as rewriting the code but still the same issue arises and I was wondering how to fix this issue.
This program will at some point compile data from 3 different sensors and do its various calculations within these separate loops and print to serial in a table that can then be saved or exported. The only sensor attached at the moment is a ultrasonic sensor that measures the distance it is from a surface. (last 2 groups of code have a basic print function just so the loop is occupied)
Here is the code:
#include <CapacitiveSensor.h>

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 = 5;     // ms for cycle of event 2  
long delay3 = 25;    // ms for cycle of event 3  
long delay4 = 10;

// 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 = 1; // Number or triggered milliseconds to start event2  
int MAX3 = 5; // Number or triggered milliseconds to start event3  
int MAX4 = 2;

// Initialisation  
setup {  
     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  
loop() {  

     // 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 ============== 

event1() {  
  long duration, distance;
  digitalWrite(trigPin,HIGH);
  delay(100);
  digitalWrite(trigPin, LOW);
  duration=pulseIn(echoPin, HIGH);
  distance =(duration/2)/29.1;
}  

event2() {  
Serial.print("work")
}  

event3() {   
Serial.print("work")
}  

I am very new to coding so there will be stupid mistakes hidden amongst this I can guarantee it.  

user31106: Function declarations start with a type:
void setup() {

}

void loop() {

}

void means the function doesn't return a value.

user30009: Yeah you never defined setup or loop which need the void before them.
void setup(){

}



void loop(){

} 


user10794: All your functions (including setup and loop) need a type as part of the declaration. This for example:
event2() {  
Serial.print("work")
}  

Should be:
void event2() {  
  Serial.print("work");
  }

Note also the semicolon after the Serial.print function call.
I have a page that explains the basics.
On that page is a diagram that breaks down what a function declaration looks like:


user29796: You have a problem with function definition. Let me explain with an example.
int kPinLed = 8; // LED - Pin 8

void setup()
{
  pinMode(kPinLed, OUTPUT); // LED as output
}

void loop()
{
  ledFun(); //Create LED Function
}

//Now write function's code with type, here "void"

void ledFun()
{
  digitalWrite(kPinLed, HIGH); //LED ON
  delay(1000);
  digitalWrite(kPinLed, LOW);  //LED OFF
  delay(1000);
}

Same things you have to do with your code. Just write properly function's type. I hope this will help you.

32143: <p>Was trying to work some code that I found online to suit my needs and it continues to show the same error <strong>'setup' does not name a type</strong>. I have tried setting it to void, Void as well as rewriting the code but still the same issue arises and I was wondering how to fix this issue.</p>

<p>This program will at some point compile data from 3 different sensors and do its various calculations within these separate loops and print to serial in a table that can then be saved or exported. The only sensor attached at the moment is a ultrasonic sensor that measures the distance it is from a surface. (last 2 groups of code have a basic print function just so the loop is occupied)</p>

<p>Here is the code:</p>

<pre><code>#include &lt;CapacitiveSensor.h&gt;

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 = 5;     // ms for cycle of event 2  
long delay3 = 25;    // ms for cycle of event 3  
long delay4 = 10;

// 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 = 1; // Number or triggered milliseconds to start event2  
int MAX3 = 5; // Number or triggered milliseconds to start event3  
int MAX4 = 2;

// Initialisation  
setup {  
     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  
loop() {  

     // 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 &gt;= 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 ============== 

event1() {  
  long duration, distance;
  digitalWrite(trigPin,HIGH);
  delay(100);
  digitalWrite(trigPin, LOW);
  duration=pulseIn(echoPin, HIGH);
  distance =(duration/2)/29.1;
}  

event2() {  
Serial.print("work")
}  

event3() {   
Serial.print("work")
}  
</code></pre>

<p>I am very new to coding so there will be stupid mistakes hidden amongst this I can guarantee it.  </p>
 31106: <p>Function declarations start with a type:</p>

<pre><code>void setup() {

}

void loop() {

}
</code></pre>

<p>void means the function doesn't return a value.</p>
 30009: <p>Yeah you never defined setup or loop which need the void before them.</p>

<pre><code>void setup(){

}



void loop(){

} 
</code></pre>
 10794: <p>All your functions (including setup and loop) need a type as part of the declaration. This for example:</p>

<pre><code>event2() {  
Serial.print("work")
}  
</code></pre>

<p>Should be:</p>

<pre><code>void event2() {  
  Serial.print("work");
  }
</code></pre>

<p>Note also the semicolon after the <code>Serial.print</code> function call.</p>

<p>I have <a href="https://www.gammon.com.au/forum/?id=13900" rel="nofollow noreferrer">a page that explains the basics</a>.</p>

<p>On that page is a diagram that breaks down what a function declaration looks like:</p>

<p><a href="https://i.stack.imgur.com/p9nfP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p9nfP.png" alt="Function definitions"></a></p>
 29796: <p>You have a problem with function definition. Let me explain with an example.</p>

<pre><code>int kPinLed = 8; // LED - Pin 8

void setup()
{
  pinMode(kPinLed, OUTPUT); // LED as output
}

void loop()
{
  ledFun(); //Create LED Function
}

//Now write function's code with type, here "void"

void ledFun()
{
  digitalWrite(kPinLed, HIGH); //LED ON
  delay(1000);
  digitalWrite(kPinLed, LOW);  //LED OFF
  delay(1000);
}
</code></pre>

<p>Same things you have to do with your code. Just write properly function's type. I hope this will help you.</p>
