Arduino IDE to Tinkercad errors

I'm relatively new to coding, and brand new to arduino and c++. I'm making a random number generator that doesnt repeat in order to light up some LEDs. When i compile in IDE, it goes just fine, bur when i copy and paste into tinkercad to run the sim, it gives this error, "invalid conversion from 'void (*)() to 'int [-fpermissive]. Any advice?




//delay time variable
#define d 200
#define delay50 200
#define VALSWANTED 6

int myled[] = {
  3,
  4,
  5,
  6,
  7,
  8,
  9,
};
int num_of_leds;
//led pins:
int led1 = 9;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
//button  pin:
int button = 2;
//variable of the result:
int result;
void setup() {
  long randomVals[VALSWANTED];
  long rand;
  int count = 0;

  memset(randomVals, 0, sizeof(randomVals));

  Serial.begin(9600);

  randomSeed(analogRead(0));
  while (count < VALSWANTED) {
    rand = random(0, 6);  // <----- THIS LINE GOT DELETED SOMEHOW???
    if (randomVals[rand] == 0) {
      randomVals[rand] = count + 1;
      count++;
    }
  }
  for (int i = 0; i < VALSWANTED; i++) {
    Serial.println(randomVals[i]);
  }
  num_of_leds = sizeof(myled) / sizeof(int);
  for (int i = 0; i < num_of_leds; i++) {
    pinMode(myled[i], OUTPUT);
  }
  //leds as OUTPUT
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  //button as INPUT_PULLUP (sends LOW when pressed)
  pinMode(button, INPUT_PULLUP);

  delay(0);
  ledonn();
  delay(1000);
  ledoff();
  delay(1000);
  for (int i = 0; i < 5; i++) { pattern1(); }
  ledoff();
  delay(1000);
}
void ledonn() {
  for (int i = 0; i < num_of_leds; i++) {
    digitalWrite(myled[i], HIGH);
  }
}
void ledoff() {
  for (int i = 0; i < num_of_leds; i++) {
    digitalWrite(myled[i], LOW);
  }
}


void pattern1() {
  for (int i = 0; i < num_of_leds; i++) {
    digitalWrite(myled[i], HIGH);
    delay(delay50);
    digitalWrite(myled[i], LOW);
  }
}



void loop() {
  if (digitalRead(button) == LOW) {
    result = pattern1;      **<--- //error is here**
  }
}

memset(randomVals, 0, VALSWANTED);

void loop() {
  if (digitalRead(button) == LOW) {
    pattern1();      //**<--- //error is here**
  }
}

That is strange. I would expect the IDE to give that same message that you see in TinkerCAD.

result = pattern1;

What was this line expected to achieve?

pattern1(); is meant to use
"void pattern1() {
for (int i = 0; i < num_of_leds; i++) {
digitalWrite(myled[i], HIGH);
delay(delay50);
digitalWrite(myled[i], LOW);
}
}" and oscillate the lights in sequence. Im also trying to make it so that when "button" is pushed, it will cycle, and then pick a random number LED without repeating

But you didn't put pattern1();. You put pattern1;. In C/C++, if you don't put the () after the function's name, the function is not executed. Without the (), the result is the address of the function. So you assigned the address of the function to the variable result.

If you were trying the execute the function, why did you assign it's return value to result? It is a void function, so there is no return value.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.