Here's my code its not finished but it keeps saying "error: a function-definition is not allowed here before ' { ' token" and i dont know why.
#include <Servo.h>
Servo esc;
int j;
int LEDpin1 = 13;
unsigned long timer[5];
byte last_channel[4];
int input[4];
void setup() {
{
PCICR |= (1 << PCIE0);
PCMSK0 |= (1 << PCINT0);
PCMSK0 |= (1 << PCINT1);
PCMSK0 |= (1 << PCINT2);
PCMSK0 |= (1 << PCINT3);
Serial.begin(9600);
}
{
delay(5000); //Delay to give me enough time to control esc to battery
esc.attach(9);
for(int i=0; i<1000; i++) //Arming
{
esc.write(0);
delay(20);
}
{
pinMode(LEDpin1, OUTPUT);
}
}
void loop() {
{
print();
}
ISR(PCINT0_vect) {
timer[0] = micros();
// channel 1 ---------------
if(last_channel[0] == 0 && PINB & B00000001 ) {
last_channel[0] = 1;
timer[1] = timer[0];
}
else if(last_channel[0] == 1 && !(PINB & B00000001) ) {
last_channel[0] = 0;
input[0] = timer[0] - timer[1];
}
// channel 2 ---------------
if(last_channel[1] == 0 && PINB & B00000010 ) {
last_channel[1] = 1;
timer[2] = timer[0];
}
else if(last_channel[1] == 1 && !(PINB & B00000010) ) {
last_channel[1] = 0;
input[1] = timer[0] - timer[2];
}
// channel 3 ---------------
if(last_channel[2] == 0 && PINB & B00000100 ) {
last_channel[2] = 1;
timer[3] = timer[0];
}
else if(last_channel[2] == 1 && !(PINB & B00000100) ) {
last_channel[2] = 0;
input[2] = timer[0] - timer[3];
}
// channel 4 ---------------
if(last_channel[3] == 0 && PINB & B00001000 ) {
last_channel[3] = 1;
timer[4] = timer[0];
}
else if(last_channel[3] == 1 && !(PINB & B00001000) ) {
last_channel[3] = 0;
input[3] = timer[0] - timer[4];
}
}
{
if (input[0] > 2000){
digitalWrite(LEDpin1, HIGH);
}
}
}
void print() {
Serial.print(input[0]);
Serial.print(" - ");
Serial.print(input[1]);
Serial.print(" - ");
Serial.print(input[2]);
Serial.print(" - ");
Serial.println(input[3]);
}
Use tools -> autoformat to properly indent your code. I think that the problem will become clear; it looks like you have a { or } in the wrong place.
When posting code on the forum, place it between [code] and [/code].
Easier to read, easier to copy.
thanks ill see if that works
You really need to read up on when/where/how to use curly braces. They are not just sprinkled into the code at random. You have WAY too many...
Regards,
Ray L.
What did not fix it? If you made a change to your code, post the updated code.
And autofornat will indeed not fix it but might make it more easily identifiable where the problem is.
i'm new to coding and still don't understand where the problem is
[
#include <Servo.h>
Servo esc;
int j;
int LEDpin1 = 13;
unsigned long timer[5];
byte last_channel[4];
int input[4];
void setup() {
{
PCICR |= (1 << PCIE0);
PCMSK0 |= (1 << PCINT0);
PCMSK0 |= (1 << PCINT1);
PCMSK0 |= (1 << PCINT2);
PCMSK0 |= (1 << PCINT3);
Serial.begin(9600);
}
{
delay(5000); //Delay to give me enough time to control esc to battery
esc.attach(9);
for (int i = 0; i < 1000; i++) //Arming
{
esc.write(0);
delay(20);
}
{
pinMode(LEDpin1, OUTPUT);
}
}
void loop()
print();
ISR(PCINT0_vect)
timer[0] = micros();
// channel 1 ---------------
if (last_channel[0] == 0 && PINB & B00000001 ) {
last_channel[0] = 1;
timer[1] = timer[0];
}
else if (last_channel[0] == 1 && !(PINB & B00000001) ) {
last_channel[0] = 0;
input[0] = timer[0] - timer[1];
}
// channel 2 ---------------
if (last_channel[1] == 0 && PINB & B00000010 ) {
last_channel[1] = 1;
timer[2] = timer[0];
}
else if (last_channel[1] == 1 && !(PINB & B00000010) ) {
last_channel[1] = 0;
input[1] = timer[0] - timer[2];
}
// channel 3 ---------------
if (last_channel[2] == 0 && PINB & B00000100 ) {
last_channel[2] = 1;
timer[3] = timer[0];
}
else if (last_channel[2] == 1 && !(PINB & B00000100) ) {
last_channel[2] = 0;
input[2] = timer[0] - timer[3];
}
// channel 4 ---------------
if (last_channel[3] == 0 && PINB & B00001000 ) {
last_channel[3] = 1;
timer[4] = timer[0];
}
else if (last_channel[3] == 1 && !(PINB & B00001000) ) {
last_channel[3] = 0;
input[3] = timer[0] - timer[4];
}
if (input[0] > 2000)
{
digitalWrite(LEDpin1, HIGH);
}
void print()
Serial.print(input[0]);
Serial.print(" - ");
Serial.print(input[1]);
Serial.print(" - ");
Serial.print(input[2]);
Serial.print(" - ");
Serial.println(input[3]);
]
What don't you understand when I explained how to post code on the forum?
To fix your problem, find your void loop in your code and change that part to
void loop()
{
print();
}
for starters. There might be more wrong though.