Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpIntegration › DC Motor - LED conflict?

Page Index Toggle Pages: 1
DC Motor - LED conflict? (Read 6516 times)
09/19/07 at 17:35:26

mga   Offline
YaBB Newbies

Posts: 41
*
 
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

 
IP Logged
 
Reply #1 - 09/19/07 at 20:58:36

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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);
}
 
IP Logged
 
Reply #2 - 09/20/07 at 00:28:30

mga   Offline
YaBB Newbies

Posts: 41
*
 
Hi

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

Thanks
 
IP Logged
 
Page Index Toggle Pages: 1