Hello People,
I really need some help!
I can't get mij servo running after I push my FSR (push-sensor).
The loop should be as followed:
Push the FSR
If the FSR is Pushed, start the Servo
After the Servo has made his 180 degree turn and has gone back to the 0 degree position, three LEDs should get burning after each other.
I've got the servo running and afterwards the LEDs go on, but this action must be activated by pushing the FSR!
I've got some code, but I can't combine them, cause my knowledge isn't that good! Can someone please help me?!?!
The code for activating the Servo and afterwards the LEDs:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int ledPin = 9 ; // LED connected to digital pin 9
int ledPin1 = 10 ;
int ledPin2 = 11 ;
int ledPin3 = 3;
// The setup() method runs once, when the sketch starts
void setup() {
myservo.attach(5); // attaches the servo on pin 5 to the servo object
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
for(pos = 0; pos < 180; pos +=1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos >=1; pos -=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin1, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin2, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin3, HIGH); // set the LED on
delay(1000); // wait for a second
}
And the code for the FSR:
const int analogPin = 5; // pin that the sensor is attached to
const int ledPin = 11; // pin that the LED is attached to
const int threshold = 20; // an arbitrary threshold level that's in the range of the analog input
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);
// if the analog value is high enough, turn on the LED:
if (analogValue > threshold) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin,LOW);
}
// print the analog value:
Serial.println(analogValue, DEC);
}
Someone PLZ PLZ PLZ help?! All my thanks in advance!