Hi,
First off, HI! pretty new to this but eager to make some stuff. Maybe you can help me with my first project.
I'll be using the Arduino to move about 6 servos when a button is pushed/switch flicked to move components on a floor-standing lamp. So the lamp will turn on, things move to one position. Lamp is turned off, things move back to original position. Simple, right?
I'm butchering the "edge detection" code to sense when the button is pushed, and to move a single servo appropriately, see below. But I'm getting a large error when it is compiled, its as if the library isnt there, but it is. I'm assuming it's a simple mistake on my part.
/*
/*
State change detection (edge detection)
Often, you don't need to know the state of a digital input all the time,
but you just need to know when the input changes from one state to another.
For example, you want to know when a button goes from OFF to ON. This is called
state change detection, or edge detection.
This example shows how to detect when a button or button changes from off to on
and on to off.
The circuit:
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* LED attached from pin 13 to ground (or use the built-in LED on
most Arduino boards)
created 27 Sep 2005
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/ButtonStateChange
*/
#include <Servo.h>
// this constant won't change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
Servo myservo;
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
myservo.attach(9); //attach servo to pin 9
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter % 2 == 0) {
myservo.write(180);
}
else {
myservo.write(0);
}
}
The error when compiling: C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:56:23: error: WProgram.h: No such file or directory
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In function 'void handle_interrupts(timer16_Sequence_t, volatile uint16_t*, volatile uint16_t*)':
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'LOW' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'digitalWrite' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'HIGH' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'digitalWrite' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:126: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: At global scope:
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:266: error: 'boolean' does not name a type
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In constructor 'VarSpeedServo::VarSpeedServo()':
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:283: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'uint8_t VarSpeedServo::attach(int, int, int)':
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'OUTPUT' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'pinMode' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:304: error: 'isTimerActive' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::detach()':
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:315: error: 'isTimerActive' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::write(int)':
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:326: error: 'map' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::writeMicroseconds(int)':
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: 'byte' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: expected ;' before 'channel' C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:335: error: 'channel' was not declared in this scope C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:343: error: 'clockCyclesPerMicrosecond' was not declared in this scope C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::slowmove(int, uint8_t)': C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:377: error: 'map' was not declared in this scope C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: 'byte' was not declared in this scope C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: expected
;' before 'channel'
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:381: error: 'channel' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:388: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::read()':
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:407: error: 'map' was not declared in this scope
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::readMicroseconds()':
C:\Users\Chris\Programmes\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:414: error: 'clockCyclesPerMicrosecond' was not declared in this scope
Again, I'm hoping it's a simple fix as I'm very eager to get this finished, it's been in the making for literally months. Any help is much appreciated and I'll post pics, video etc here when I complete it.
Thanks