Hi all! I am very new to the arduino, and to be very honest, elektronics in general. Here I am getting my feet wet with a project I would like to present at school: a real-life heartbeat lamp. The goal is to get a solenoid to move the skin of the lamp as if it were beating. I got a piece of code to get a LED to do the same thing from another topic. However, I can't get the solenoid to join in. When I get this to work, I want the pace of the heartbeat to be temperature controlled (15 degrees C = slow, 23 degrees
C = very fast)
When I run the code like this, the solenoid will just be activated. There is no "lub-lub"of the heart.
(the beat I got from elCalvoMike)
//Heartshaped_lamp LED
byte LED = 11;
int potPin = 2;
int solPin = 10;
int i = 0;
int pmw = 255; //set PWM max - intensity
int rate = 20; //this is the beats per minute (60000 ms)
//because there are two beats to simulate the 'lub-dub' of the heart,
//a 60 beat heart rate is only a value of 30 in the rate variable
//the delay is the key to this programs realism - divide the rate
//into a minute, then weight it and divide by the pmw
//you can modify the weight by changing the fractions (i.e .1, .2,.1, .6)
//but to keep the timing correct, they should total 1
//.1+.2+.1+.6 = 1
int potValue;
int race;
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(solPin, OUTPUT);
pinMode(potPin, INPUT);
}
void loop()
{
potValue = analogRead(potPin);
Serial.println(potValue);
/*if (potValue < 146)
{race = 80000;}
if (potValue < 292)
{race = 70000;}
if (potValue < 438)
{race = 60000;}
if (potValue < 584)
{race = 50000;}
if (potValue < 730)
{race = 40000;}*/
for (i = 0; i < pmw; i++)
{
analogWrite(LED,i);
digitalWrite(solPin, HIGH);
delay(((60000/rate)*.1)/pmw);
}
digitalWrite(solPin, LOW);
for (i = pmw; i > 0; i--)
{
analogWrite(LED,i);
digitalWrite(solPin, HIGH);
delay(((60000/rate)*.2)/pmw);
}
digitalWrite(solPin, LOW);
for (i = 0; i < pmw; i++)
{
analogWrite(LED,i);
digitalWrite(solPin, HIGH);
delay(((60000/rate)*.1)/pmw);
}
digitalWrite(solPin, LOW);
for (i = pmw; i > 0; i--)
{
analogWrite(LED,i);
digitalWrite(solPin, HIGH);
delay(((60000/rate)*.6)/pmw);
}
digitalWrite(solPin, LOW);
}