Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Integration >> DC Motor - LED conflict?
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1190223327

Message started by mga on 09/19/07 at 17:35:26

Title: DC Motor - LED conflict?
Post by mga on 09/19/07 at 17:35:26
Hi

I am trying out turning on a LED and a motor at the same time. For some reason, if there is a LED the motor won't turn on (usb-powered and externally powered). It is a 3V DC Motor. The code is:

int led_ = 48;
int motorpin = 0;

void setup () {
 pinMode(led_,OUTPUT);
}

void loop() {
 analogWrite(motorpin, 255);
 digitalWrite(led_,HIGH);
}

What am I doing wrong?

Thanks

Mauricio


Title: Re: DC Motor - LED conflict?
Post by barragan on 09/19/07 at 20:58:36
hi, there´s nothing wrong with the code below, perhaps giving it a delay in the loop could be fine. Note that analogWrite works only on pins 0-5 of the PWM output pins section of the board, so make sure you´re using that set of pins for that. http://wiring.org.co/ioboard/index.html#040

int led_ = 48;
int motorpin = 0;

void setup () {
 pinMode(led_,OUTPUT);
}
 
void loop() {  
 analogWrite(motorpin, 255);
 digitalWrite(led_,HIGH);
 delay(100);
}

Title: Re: DC Motor - LED conflict?
Post by mga on 09/20/07 at 00:28:30
Hi

The delay did "fix" it and now both LED and motor are on.

Thanks

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.