Hi I'm new in electronic and I have a Teensy++ and when I try to combine 2 working programes, one doesn't work
the first is a extensometer that control the angle of a servo
the second is a RGB LED increasing light intensity with a extensometer
Together the LED dont open at all... I did few test and found that digitalwrite could open the LED but only on a constant value. So I puted a delay following the extensometer resistance to make it blink faster when there would be more flexion, but the servo started to choke, due to the too long delay it was taking to update his angle from the program. Im pretty sure the problem is in the ''Analogwrite'' command but I dont know how to fix it.
thank you
Dom
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int val; // variable to read the value from the analog pin
void setup()
{ Serial.begin(38400); to read the value on computer
pinMode(15, OUTPUT); its a blue LED
myservo.attach(26); // attaches the servo on pin 9 to the servo object
}
void loop()
{
Serial.println(analogRead(39));to read the value on computer
analogWrite(15, 310-analogRead(39)); /light changing with flexions (DOESNT WORK)/
val = analogRead(38); // reads the value of the extentiometer (value between 0 and 1023)
val = map((7.3*(val-180)), 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) 179
myservo.write(val); // sets the servo position according to the scaled value
delay(5); // waits for the servo to get there 15
}