0

I'm trying to light up 81 on a 4-digit 7-segment display, but when I try to upload the code to my Uno R3 it gives me this error: "a function-definition is not allowed here before '{' token". I'm new to Arduino and this is my second day using it, so I would like to get help and know how to fix this problem. Here is my code:

int isej1 = 2;
int isej2 = 3;
int vienetas[] = { 12, 11 };
int astuonetas[] = { 13, 12, 11, 10, 9, 8, 7 };

void setup() {
  pinMode (vienetas[2], OUTPUT);
  pinMode (astuonetas[8], OUTPUT);
  pinMode (isej1, OUTPUT);
  pinMode (isej2, OUTPUT);
}

void uz_vien() {
  digitalWrite (vienetas[0], HIGH);
  digitalWrite (vienetas[1], HIGH);
}

void uz_astuon() {
  digitalWrite (astuonetas[0], HIGH);
  digitalWrite (astuonetas[1], HIGH);
  digitalWrite (astuonetas[2], HIGH);
  digitalWrite (astuonetas[3], HIGH);
  digitalWrite (astuonetas[4], HIGH);
  digitalWrite (astuonetas[5], HIGH);
  digitalWrite (astuonetas[6], HIGH);
}

void is_vien() {
  digitalWrite (vienetas[0], LOW);
  digitalWrite (vienetas[1], LOW);
}

void is_astuon() {
  digitalWrite (astuonetas[0], LOW);
  digitalWrite (astuonetas[1], LOW);
  digitalWrite (astuonetas[2], LOW);
  digitalWrite (astuonetas[3], LOW);
  digitalWrite (astuonetas[4], LOW);
  digitalWrite (astuonetas[5], LOW);
  digitalWrite (astuonetas[6], LOW);

void loop() {
  digitalWrite (isej1, LOW);
  digitalWrite (isej2, HIGH);
  void uz_vien();
  delay(5);
  void is_vien();
  digitalWrite (isej1, HIGH);
  digitalWrite (isej2, LOW);
  void uz_astuon();
  delay(5);
  void is_astuon();
}
3

You are missing a "}" just before loop

  void is_astuon() {
    digitalWrite (astuonetas[0], LOW);
    digitalWrite (astuonetas[1], LOW);
    digitalWrite (astuonetas[2], LOW);
    digitalWrite (astuonetas[3], LOW);
    digitalWrite (astuonetas[4], LOW);
    digitalWrite (astuonetas[5], LOW);
    digitalWrite (astuonetas[6], LOW);
   } // <- missing here.
  void loop() {
| improve this answer | |
2

The importance of proper indentation is clear here...

I thought you were missing a closing curly braces. When you type code, press regularly cmd/ctrl-T to ident your code -- it helps catching mistakes. You are indeed missing one, for is_astuon().

Moreover these lines are wrong too:

**void** uz_vien();
delay(5);
**void** is_vien();
digitalWrite (isej1, HIGH);
digitalWrite (isej2, LOW);
**void** uz_astuon();

The void part is not needed and creates the error.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.