Go Down

Topic: Error: '~' was not declared in this scope (Read 11436 times) previous topic - next topic

Frustrated

I recently bought an Arduino Uno for use in my robotics project that consists of two motors. Due to my only testing one right now, I found some code online and modified it for use by one servo (continues rotation from Spark Fun).

Here is the snippet of code as is:

Code: [Select]

#include <Servo.h>

Servo first; // create servo object

int firstservopin = 9;                               // digital output to which signal wire(yellow) of first servo is connected

void setup() {
  first.attach(firstservopin); // attach the servo to digital output 8
  first.write(90); // center the servo
   delay(1000);
}

void loop() {

  first.write(0);                        // move first servo to pos 0
  delay(1000);
  first.write(180);               // move first servo to pos 180
  delay(1000);
}


After trying to verify this code in the Arduino IDE, I got these error messages:

Code: [Select]

C:\Users\Owner\Documents\Arduino\libraries\Servo\Servo.cpp: In member function 'uint8_t Servo::attach(int)':
C:\Users\Owner\Documents\Arduino\libraries\Servo\Servo.cpp:28: error: 'digitalWrite' was not declared in this scope
C:\Users\Owner\Documents\Arduino\libraries\Servo\Servo.cpp:29: error: 'OUTPUT' was not declared in this scope
C:\Users\Owner\Documents\Arduino\libraries\Servo\Servo.cpp:29: error: 'pinMode' was not declared in this scope
C:\Users\Owner\Documents\Arduino\libraries\Servo\Servo.cpp: In member function 'void Servo::write(int)':
C:\Users\Owner\Documents\Arduino\libraries\Servo\Servo.cpp:52: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Owner\Documents\Arduino\libraries\Servo\Servo.cpp: In static member function 'static void Servo::refresh()':
C:\Users\Owner\Documents\Arduino\libraries\Servo\Servo.cpp:74: error: 'millis' was not declared in this scope
C:\Users\Owner\Documents\Arduino\libraries\Servo\Servo.cpp:107: error: 'digitalWrite' was not declared in this scope
C:\Users\Owner\Documents\Arduino\libraries\Servo\Servo.cpp:109: error: 'TCNT0' was not declared in this scope
C:\Users\Owner\Documents\Arduino\libraries\Servo\Servo.cpp:124: error: 'digitalWrite' was not declared in this scope


After Googling for the solution to this problem to no avial, I turn to the community for help as to what I may have done wrong and a possible solution to the problem.

Thank You,
Frustrated

Grumpy_Mike

That code you posted compiles fine for a Uno on my machine. Maybe you have an old version of the servo library or you have an old version of the IDE.

Frustrated

I re installed the Arduino IDE and I continue to get the same error messages.

Grumpy_Mike


Frustrated

SOLUTION: I just deleted  all traces of Arduino related software from my computer, on top of uninstalling the Arduino IDE (ie: I searched for 'servo' and deleted all search results, doing the same for 'Arduino'). Then, upon re installation of the Arduino software, everything worked fine.

Special thanks to Grumpy_Mike helping out, and eventually leading to the solution..

~Frustrated

Go Up