Pages: [1]   Go Down
Author Topic: Analogwrite problem  (Read 760 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
 }
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

please use code tags when posting
ehm did you forgot // marks in your setup part.
is see you also use it once / but it should be double //
oh and i think analog write can only have values between 0 and 255
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26503
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Serial.println(analogRead(39));to read the value on computer
What is the compiler supposed to do there?
You need // after the ;
« Last Edit: September 10, 2012, 06:04:17 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks PGTBOOS, i'll try to learn to use code tag
ill try to change the // marks and change the values to be between 0 and 255
your help is sincerly appreciated


the compiler is just a witness that the program works
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26503
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, the compiler is just a witness to the fact that the program is syntactically correct.
It cannot guarantee that the program will behave correctly.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 502
Posts: 19086
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks PGTBOOS, i'll try to learn to use code tag

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.
Logged


Pages: [1]   Go Up
Jump to: