so iv built a prototype of a plushy heart that glows its heart beat. It has a potentiometer to controll the rate of wich the heart beats.
it works fine and all, but now i want to add a small servo to make the heart physicaly beat, with the glowing LED, but i also want the servo's beating to be controlled by the same POT that controlls the led.
im new to coding but i managed to merge my original code with the sweep example code.
but it just wont work.
LED heart beat
int sensorPin = 0; // select the input pin for the potentiometer
int ledPin = 9; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// nothing happens in setup
}
void loop() {
// This part need to stay as it was in the original code
for(int fadeValue = 0; fadeValue <= 255; fadeValue +=5 ) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// sets the delay with the pot value
delay(analogRead(sensorPin));
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// sets the delay with the pot value
delay(analogRead(sensorPin));
}
}
LED heart beat + servo
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 1; // variable to store the servo position
int sensorPin = 0; // select the input pin for the potentiometer
int ledPin = 9; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
myservo.attach(10); // attaches the servo on pin 10 to the servo object
}
void loop() {
// This part need to stay as it was in the original code
for(int fadeValue = 0; fadeValue <= 255; fadeValue +=5 ) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// sets the delay with the pot value
delay(analogRead(sensorPin));
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// sets the delay with the pot value
delay(analogRead(sensorPin));
}
{
for(pos = 1; 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(analogRead(sensorPin)); // waits ??? 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'
(analogRead(sensorPin)); // waits ??? for the servo to reach the position
}
}
}
please if some one can help me and point out what iv done wrong?
or if some one can fix the code for me, im willing to sent $5 over paypal as a last resort.
-Gab