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.
