Pages: [1]   Go Down
Author Topic: The new 1.0.2 is showing some thing about undefined reference to `setup'  (Read 996 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 3
Posts: 268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm getting    undefined reference to `setup'
But I don't see why  using 1.0.2 ide

Code:
const int keyMin = 0;      // Keymin, discovered through experiment
const int keyMax = 600;    // keymax, discovered through experiment
void loop() {
  // read the sensor:
  int key = analogRead(A0);
  // map the sensor range to a range of four options:
  int keyValue = map(key, keyMin, keyMax, 0, 3);

  // do something different depending on the
  // range value:
  switch (keyValue) {
  case 0:    // your hand is on the sensor
    Serial.println("button1");
    break;
  case 1:    // your hand is close to the sensor
    Serial.println("button2");
    break;
  case 2:    // your hand is a few inches from the sensor
    Serial.println("button3");
    break;
  case 3:    // your hand is nowhere near the sensor
    Serial.println("button4t");
    break;
  }
  delay(1);        // delay in between reads for stability
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

An Arduino sketch requires to define a `setup' function, even when it is empty. Such function is used for setting up things you may use on the `loop' function. Since you use the Serial object, it is a good idea to initialize it on the `setup' function. Just add this to your code:

Code:
void setup() {
  Serial.begin(9600);
}
Logged

Offline Offline
Sr. Member
****
Karma: 3
Posts: 268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dang that did the job I had that in there but I removed it some how Thanks
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2396
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you follow the links in the playground you can find the code that the IDE adds.

In this case it adds main() which is required for all C/C++ programs.

main() looks like this

Code:
void main(){
  init(); // do things to set up every thing for all programs
  setup();
  while(1==1){
     loop();
  }
}

hence the need to provide both loop() and setup();

Mark
Logged

Pages: [1]   Go Up
Jump to: